home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / guile0.4.lcm / share / guile / slib / slib.info < prev    next >
Encoding:
GNU Info File  |  2004-01-06  |  444.0 KB  |  11,432 lines

  1. This is Info file slib.info, produced by Makeinfo version 1.68 from the
  2. input file slib.texi.
  3.  
  4. INFO-DIR-SECTION The Algorithmic Language Scheme
  5. START-INFO-DIR-ENTRY
  6. * SLIB: (slib).         Scheme Library
  7. END-INFO-DIR-ENTRY
  8.  
  9.   This file documents SLIB, the portable Scheme library.
  10.  
  11.   Copyright (C) 1993 Todd R. Eigenschink
  12. Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 Aubrey           |
  13. Jaffer                                                                        |
  14.  
  15.   Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.   Permission is granted to copy and distribute modified versions of this
  20. manual under the conditions for verbatim copying, provided that the
  21. entire resulting derived work is distributed under the terms of a
  22. permission notice identical to this one.
  23.  
  24.   Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that this permission notice may be stated in a
  27. translation approved by the author.
  28.  
  29. 
  30. File: slib.info,  Node: Top,  Next: The Library System,  Prev: (dir),  Up: (dir)
  31.  
  32. "SLIB" is a portable library for the programming language "Scheme".  It
  33. provides a platform independent framework for using "packages" of
  34. Scheme procedures and syntax.  As distributed, SLIB contains useful
  35. packages for all Scheme implementations.  Its catalog can be
  36. transparently extended to accomodate packages specific to a site,
  37. implementation, user, or directory.
  38.  
  39. * Menu:
  40.  
  41. * The Library System::          How to use and customize.
  42. * Scheme Syntax Extension Packages::
  43. * Textual Conversion Packages::
  44. * Mathematical Packages::
  45. * Database Packages::
  46. * Other Packages::
  47. * About SLIB::                  Install, etc.
  48. * Index::
  49.  
  50. 
  51. File: slib.info,  Node: The Library System,  Next: Scheme Syntax Extension Packages,  Prev: Top,  Up: Top
  52.  
  53. The Library System
  54. ******************
  55.  
  56. * Menu:
  57.  
  58. * Feature::                     SLIB names.
  59. * Requesting Features::
  60. * Library Catalogs::
  61. * Catalog Compilation::
  62. * Built-in Support::
  63. * About this manual::
  64.  
  65. 
  66. File: slib.info,  Node: Feature,  Next: Requesting Features,  Prev: The Library System,  Up: The Library System
  67.  
  68. Feature
  69. =======
  70.  
  71. SLIB denotes "features" by symbols.  SLIB maintains a list of features
  72. supported by the Scheme "session".  The set of features provided by a
  73. session may change over time.  Some features are properties of the
  74. Scheme implementation being used.  The following features detail what
  75. sort of numbers are available from an implementation.
  76.  
  77.    * 'inexact
  78.  
  79.    * 'rational
  80.  
  81.    * 'real
  82.  
  83.    * 'complex
  84.  
  85.    * 'bignum
  86.  
  87. Other features correspond to the presence of sets of Scheme procedures
  88. or syntax (macros).
  89.  
  90.  - Function: provided? FEATURE
  91.      Returns `#t' if FEATURE is supported by the current Scheme session.
  92.  
  93.  - Procedure: provide FEATURE
  94.      Informs SLIB that FEATURE is supported.  Henceforth `(provided?
  95.      FEATURE)' will return `#t'.
  96.  
  97.      (provided? 'foo)    => #f
  98.      (provide 'foo)
  99.      (provided? 'foo)    => #t
  100.  
  101. 
  102. File: slib.info,  Node: Requesting Features,  Next: Library Catalogs,  Prev: Feature,  Up: The Library System
  103.  
  104. Requesting Features
  105. ===================
  106.  
  107. SLIB creates and maintains a "catalog" mapping features to locations of
  108. files introducing procedures and syntax denoted by those features.
  109.  
  110. At the beginning of each section of this manual, there is a line like
  111. `(require 'FEATURE)'.  The Scheme files comprising SLIB are cataloged
  112. so that these feature names map to the corresponding files.
  113.  
  114. SLIB provides a form, `require', which loads the files providing the
  115. requested feature.
  116.  
  117.  - Procedure: require FEATURE
  118.         * If `(provided? FEATURE)' is true, then `require' just returns
  119.           an unspecified value.
  120.  
  121.         * Otherwise, if FEATURE is found in the catalog, then the
  122.           corresponding files will be loaded and an unspecified value
  123.           returned.
  124.  
  125.           Subsequently `(provided? FEATURE)' will return `#t'.
  126.  
  127.         * Otherwise (FEATURE not found in the catalog), an error is
  128.           signaled.
  129.  
  130. The catalog can also be queried using `require:feature->path'.
  131.  
  132.  - Function: require:feature->path FEATURE
  133.         * If FEATURE is already provided, then returns `#t'.
  134.  
  135.         * Otherwise, if FEATURE is in the catalog, the path or list of
  136.           paths associated with FEATURE is returned.
  137.  
  138.         * Otherwise, returns `#f'.
  139.  
  140. 
  141. File: slib.info,  Node: Library Catalogs,  Next: Catalog Compilation,  Prev: Requesting Features,  Up: The Library System
  142.  
  143. Library Catalogs
  144. ================
  145.  
  146. At the start of a session no catalog is present, but is created with the
  147. first catalog inquiry (such as `(require 'random)').  Several sources
  148. of catalog information are combined to produce the catalog:
  149.  
  150.    * standard SLIB packages.
  151.  
  152.    * additional packages of interest to this site.
  153.  
  154.    * packages specifically for the variety of Scheme which this session
  155.      is running.
  156.  
  157.    * packages this user wants to always have available.  This catalog
  158.      is the file `homecat' in the user's "HOME" directory.
  159.  
  160.    * packages germane to working in this (current working) directory.
  161.      This catalog is the file `usercat' in the directory to which it
  162.      applies.  One would typically `cd' to this directory before
  163.      starting the Scheme session.
  164.  
  165. Catalog files consist of one or more "association list"s.  In the
  166. circumstance where a feature symbol appears in more than one list, the
  167. latter list's association is retrieved.  Here are the supported formats
  168. for elements of catalog lists:
  169.  
  170. `(FEATURE . <symbol>)'
  171.      Redirects to the feature named <symbol>.
  172.  
  173. `(FEATURE . "<path>")'
  174.      Loads file <path>.
  175.  
  176. `(FEATURE source "<path>")'
  177.      `slib:load's the Scheme source file <path>.
  178.  
  179. `(FEATURE compiled "<path>" ...)'
  180.      `slib:load-compiled's the files <path> ....
  181.  
  182. The various macro styles first `require' the named macro package, then
  183. just load <path> or load-and-macro-expand <path> as appropriate for the
  184. implementation.
  185.  
  186. `(FEATURE defmacro "<path>")'
  187.      `defmacro:load's the Scheme source file <path>.
  188.  
  189. `(FEATURE macro-by-example "<path>")'
  190.      `defmacro:load's the Scheme source file <path>.
  191.  
  192. `(FEATURE macro "<path>")'
  193.      `macro:load's the Scheme source file <path>.
  194.  
  195. `(FEATURE macros-that-work "<path>")'
  196.      `macro:load's the Scheme source file <path>.
  197.  
  198. `(FEATURE syntax-case "<path>")'
  199.      `macro:load's the Scheme source file <path>.
  200.  
  201. `(FEATURE syntactic-closures "<path>")'
  202.      `macro:load's the Scheme source file <path>.
  203.  
  204. Here is an example of a `usercat' catalog.  A Program in this directory
  205. can invoke the `run' feature with `(require 'run)'.
  206.  
  207.      ;;; "usercat": SLIB catalog additions for SIMSYNCH.     -*-scheme-*-
  208.      
  209.      (
  210.       (simsynch      . "../synch/simsynch.scm")
  211.       (run           . "../synch/run.scm")
  212.       (schlep        . "schlep.scm")
  213.      )
  214.  
  215. 
  216. File: slib.info,  Node: Catalog Compilation,  Next: Built-in Support,  Prev: Library Catalogs,  Up: The Library System
  217.  
  218. Catalog Compilation
  219. ===================
  220.  
  221. SLIB combines the catalog information which doesn't vary per user into
  222. the file `slibcat' in the implementation-vicinity.  Therefore `slibcat'
  223. needs change only when new software is installed or compiled.  Because
  224. the actual pathnames of files can differ from installation to
  225. installation, SLIB builds a separate catalog for each implementation it
  226. is used with.
  227.  
  228. The definition of `*SLIB-VERSION*' in SLIB file `require.scm' is
  229. checked against the catalog association of `*SLIB-VERSION*' to
  230. ascertain when versions have changed.  I recommend that the definition
  231. of `*SLIB-VERSION*' be changed whenever the library is changed.  If
  232. multiple implementations of Scheme use SLIB, remember that recompiling
  233. one `slibcat' will fix only that implementation's catalog.
  234.  
  235. The compilation scripts of Scheme implementations which work with SLIB
  236. can automatically trigger catalog compilation by deleting `slibcat' or
  237. by invoking a special form of `require':
  238.  
  239.  - Procedure: require 'new-catalog
  240.      This will load `mklibcat', which compiles and writes a new
  241.      `slibcat'.
  242.  
  243. Another special form of `require' erases SLIB's catalog, forcing it to
  244. be reloaded the next time the catalog is queried.
  245.  
  246.  - Procedure: require #f
  247.      Removes SLIB's catalog information.  This should be done before
  248.      saving an executable image so that, when restored, its catalog
  249.      will be loaded afresh.
  250.  
  251. Each file in the table below is descibed in terms of its file-system
  252. independent "vicinity" (*note Vicinity::.).  The entries of a catalog
  253. in the table override those of catalogs above it in the table.
  254.  
  255. `implementation-vicinity' `slibcat'
  256.      This file contains the associations for the packages comprising
  257.      SLIB, the `implcat' and the `sitecat's.  The associations in the
  258.      other catalogs override those of the standard catalog.
  259.  
  260. `library-vicinity' `mklibcat.scm'
  261.      creates `slibcat'.
  262.  
  263. `library-vicinity' `sitecat'
  264.      This file contains the associations specific to an SLIB
  265.      installation.
  266.  
  267. `implementation-vicinity' `implcat'
  268.      This file contains the associations specific to an implementation
  269.      of Scheme.  Different implementations of Scheme should have
  270.      different `implementation-vicinity'.
  271.  
  272. `implementation-vicinity' `mkimpcat.scm'
  273.      if present, creates `implcat'.
  274.  
  275. `implementation-vicinity' `sitecat'
  276.      This file contains the associations specific to a Scheme
  277.      implementation installation.
  278.  
  279. `home-vicinity' `homecat'
  280.      This file contains the associations specific to an SLIB user.
  281.  
  282. `user-vicinity' `usercat'
  283.      This file contains associations effecting only those sessions whose
  284.      "working directory" is `user-vicinity'.
  285.  
  286. 
  287. File: slib.info,  Node: Built-in Support,  Next: About this manual,  Prev: Catalog Compilation,  Up: The Library System
  288.  
  289. Built-in Support
  290. ================
  291.  
  292. The procedures described in these sections are supported by all
  293. implementations as part of the `*.init' files or by `require.scm'.
  294.  
  295. * Menu:
  296.  
  297. * Require::                     Module Management
  298. * Vicinity::                    Pathname Management
  299. * Configuration::               Characteristics of Scheme Implementation
  300. * Input/Output::                Things not provided by the Scheme specs.
  301. * Legacy::
  302. * System::                      LOADing, EVALing, ERRORing, and EXITing
  303.  
  304. 
  305. File: slib.info,  Node: Require,  Next: Vicinity,  Prev: Built-in Support,  Up: Built-in Support
  306.  
  307. Require
  308. -------
  309.  
  310.  - Variable: *features*
  311.      Is a list of symbols denoting features supported in this
  312.      implementation.  *FEATURES* can grow as modules are `require'd.
  313.      *FEATURES* must be defined by all implementations (*note
  314.      Porting::.).
  315.  
  316.      Here are features which SLIB (`require.scm') adds to *FEATURES*
  317.      when appropriate.
  318.  
  319.         * 'inexact
  320.  
  321.         * 'rational
  322.  
  323.         * 'real
  324.  
  325.         * 'complex
  326.  
  327.         * 'bignum
  328.  
  329.      For each item, `(provided? 'FEATURE)' will return `#t' if that
  330.      feature is available, and `#f' if not.
  331.  
  332.  - Variable: *modules*
  333.      Is a list of pathnames denoting files which have been loaded.
  334.  
  335.  - Variable: *catalog*
  336.      Is an association list of features (symbols) and pathnames which
  337.      will supply those features.  The pathname can be either a string
  338.      or a pair.  If pathname is a pair then the first element should be
  339.      a macro feature symbol, `source', or `compiled'.  The cdr of the
  340.      pathname should be either a string or a list.
  341.  
  342. In the following functions if the argument FEATURE is not a symbol it
  343. is assumed to be a pathname.
  344.  
  345.  - Function: provided? FEATURE
  346.      Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
  347.      or if FEATURE is supported by a file already loaded and `#f'
  348.      otherwise.
  349.  
  350.  - Procedure: require FEATURE
  351.      FEATURE is a symbol.  If `(provided? FEATURE)' is true `require'
  352.      returns.  Otherwise, if `(assq FEATURE *catalog*)' is not `#f',
  353.      the associated files will be loaded and `(provided? FEATURE)' will
  354.      henceforth return `#t'.  An unspecified value is returned.  If
  355.      FEATURE is not found in `*catalog*', then an error is signaled.
  356.  
  357.  - Procedure: require PATHNAME
  358.      PATHNAME is a string.  If PATHNAME has not already been given as
  359.      an argument to `require', PATHNAME is loaded.  An unspecified
  360.      value is returned.
  361.  
  362.  - Procedure: provide FEATURE
  363.      Assures that FEATURE is contained in `*features*' if FEATURE is a
  364.      symbol and `*modules*' otherwise.
  365.  
  366.  - Function: require:feature->path FEATURE
  367.      Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
  368.      or if FEATURE is supported by a file already loaded.  Returns a
  369.      path if one was found in `*catalog*' under the feature name, and
  370.      `#f' otherwise.  The path can either be a string suitable as an
  371.      argument to load or a pair as described above for *catalog*.
  372.  
  373. 
  374. File: slib.info,  Node: Vicinity,  Next: Configuration,  Prev: Require,  Up: Built-in Support
  375.  
  376. Vicinity
  377. --------
  378.  
  379. A vicinity is a descriptor for a place in the file system.  Vicinities
  380. hide from the programmer the concepts of host, volume, directory, and
  381. version.  Vicinities express only the concept of a file environment
  382. where a file name can be resolved to a file in a system independent
  383. manner.  Vicinities can even be used on "flat" file systems (which have
  384. no directory structure) by having the vicinity express constraints on
  385. the file name.  On most systems a vicinity would be a string.  All of
  386. these procedures are file system dependent.
  387.  
  388. These procedures are provided by all implementations.
  389.  
  390.  - Function: make-vicinity PATH
  391.      Returns the vicinity of PATH for use by `in-vicinity'.
  392.  
  393.  - Function: program-vicinity
  394.      Returns the vicinity of the currently loading Scheme code.  For an
  395.      interpreter this would be the directory containing source code.
  396.      For a compiled system (with multiple files) this would be the
  397.      directory where the object or executable files are.  If no file is
  398.      currently loading it the result is undefined.  *Warning:*
  399.      `program-vicinity' can return incorrect values if your program
  400.      escapes back into a `load'.
  401.  
  402.  - Function: library-vicinity
  403.      Returns the vicinity of the shared Scheme library.
  404.  
  405.  - Function: implementation-vicinity
  406.      Returns the vicinity of the underlying Scheme implementation.  This
  407.      vicinity will likely contain startup code and messages and a
  408.      compiler.
  409.  
  410.  - Function: user-vicinity
  411.      Returns the vicinity of the current directory of the user.  On most
  412.      systems this is `""' (the empty string).
  413.  
  414.  - Function: home-vicinity
  415.      Returns the vicinity of the user's "HOME" directory, the directory
  416.      which typically contains files which customize a computer
  417.      environment for a user.  If scheme is running without a user (eg.
  418.      a daemon) or if this concept is meaningless for the platform, then
  419.      `home-vicinity' returns `#f'.
  420.  
  421.  - Function: in-vicinity VICINITY FILENAME
  422.      Returns a filename suitable for use by `slib:load',
  423.      `slib:load-source', `slib:load-compiled', `open-input-file',
  424.      `open-output-file', etc.  The returned filename is FILENAME in
  425.      VICINITY.  `in-vicinity' should allow FILENAME to override
  426.      VICINITY when FILENAME is an absolute pathname and VICINITY is
  427.      equal to the value of `(user-vicinity)'.  The behavior of
  428.      `in-vicinity' when FILENAME is absolute and VICINITY is not equal
  429.      to the value of `(user-vicinity)' is unspecified.  For most systems
  430.      `in-vicinity' can be `string-append'.
  431.  
  432.  - Function: sub-vicinity VICINITY NAME
  433.      Returns the vicinity of VICINITY restricted to NAME.  This is used
  434.      for large systems where names of files in subsystems could
  435.      conflict.  On systems with directory structure `sub-vicinity' will
  436.      return a pathname of the subdirectory NAME of VICINITY.
  437.  
  438. 
  439. File: slib.info,  Node: Configuration,  Next: Input/Output,  Prev: Vicinity,  Up: Built-in Support
  440.  
  441. Configuration
  442. -------------
  443.  
  444. These constants and procedures describe characteristics of the Scheme
  445. and underlying operating system.  They are provided by all
  446. implementations.
  447.  
  448.  - Constant: char-code-limit
  449.      An integer 1 larger that the largest value which can be returned by
  450.      `char->integer'.
  451.  
  452.  - Constant: most-positive-fixnum
  453.      In implementations which support integers of practically unlimited
  454.      size, MOST-POSITIVE-FIXNUM is a large exact integer within the
  455.      range of exact integers that may result from computing the length
  456.      of a list, vector, or string.
  457.  
  458.      In implementations which do not support integers of practically
  459.      unlimited size, MOST-POSITIVE-FIXNUM is the largest exact integer
  460.      that may result from computing the length of a list, vector, or
  461.      string.
  462.  
  463.  - Constant: slib:tab
  464.      The tab character.
  465.  
  466.  - Constant: slib:form-feed
  467.      The form-feed character.
  468.  
  469.  - Function: software-type
  470.      Returns a symbol denoting the generic operating system type.  For
  471.      instance, `unix', `vms', `macos', `amiga', or `ms-dos'.
  472.  
  473.  - Function: slib:report-version
  474.      Displays the versions of SLIB and the underlying Scheme
  475.      implementation and the name of the operating system.  An
  476.      unspecified value is returned.
  477.  
  478.           (slib:report-version) => slib "2c8" on scm "5b1" on unix            |
  479.  
  480.  - Function: slib:report
  481.      Displays the information of `(slib:report-version)' followed by
  482.      almost all the information neccessary for submitting a problem
  483.      report.  An unspecified value is returned.
  484.  
  485.  - Function: slib:report #T
  486.      provides a more verbose listing.
  487.  
  488.  - Function: slib:report FILENAME
  489.      Writes the report to file `filename'.
  490.  
  491.           (slib:report)
  492.           =>
  493.           slib "2c8" on scm "5b1" on unix                                     |
  494.           (implementation-vicinity) is "/home/jaffer/scm/"
  495.           (library-vicinity) is "/home/jaffer/slib/"
  496.           (scheme-file-suffix) is ".scm"
  497.           loaded *features* :
  498.                   trace alist qp sort
  499.                   common-list-functions macro values getopt
  500.                   compiled
  501.           implementation *features* :
  502.                   bignum complex real rational
  503.                   inexact vicinity ed getenv
  504.                   tmpnam abort transcript with-file
  505.                   ieee-p1178 rev4-report rev4-optional-procedures hash
  506.                   object-hash delay eval dynamic-wind
  507.                   multiarg-apply multiarg/and- logical defmacro
  508.                   string-port source current-time record
  509.                   rev3-procedures rev2-procedures sun-dl string-case
  510.                   array dump char-ready? full-continuation
  511.                   system
  512.           implementation *catalog* :
  513.                   (i/o-extensions compiled "/home/jaffer/scm/ioext.so")
  514.                   ...
  515.  
  516. 
  517. File: slib.info,  Node: Input/Output,  Next: Legacy,  Prev: Configuration,  Up: Built-in Support
  518.  
  519. Input/Output
  520. ------------
  521.  
  522. These procedures are provided by all implementations.
  523.  
  524.  - Procedure: file-exists? FILENAME
  525.      Returns `#t' if the specified file exists.  Otherwise, returns
  526.      `#f'.  If the underlying implementation does not support this
  527.      feature then `#f' is always returned.
  528.  
  529.  - Procedure: delete-file FILENAME
  530.      Deletes the file specified by FILENAME.  If FILENAME can not be
  531.      deleted, `#f' is returned.  Otherwise, `#t' is returned.
  532.  
  533.  - Procedure: tmpnam
  534.      Returns a pathname for a file which will likely not be used by any
  535.      other process.  Successive calls to `(tmpnam)' will return
  536.      different pathnames.
  537.  
  538.  - Procedure: current-error-port
  539.      Returns the current port to which diagnostic and error output is
  540.      directed.
  541.  
  542.  - Procedure: force-output
  543.  - Procedure: force-output PORT
  544.      Forces any pending output on PORT to be delivered to the output
  545.      device and returns an unspecified value.  The PORT argument may be
  546.      omitted, in which case it defaults to the value returned by
  547.      `(current-output-port)'.
  548.  
  549.  - Procedure: output-port-width
  550.  - Procedure: output-port-width PORT
  551.      Returns the width of PORT, which defaults to
  552.      `(current-output-port)' if absent.  If the width cannot be
  553.      determined 79 is returned.
  554.  
  555.  - Procedure: output-port-height
  556.  - Procedure: output-port-height PORT
  557.      Returns the height of PORT, which defaults to
  558.      `(current-output-port)' if absent.  If the height cannot be
  559.      determined 24 is returned.
  560.  
  561. 
  562. File: slib.info,  Node: Legacy,  Next: System,  Prev: Input/Output,  Up: Built-in Support
  563.  
  564. Legacy
  565. ------
  566.  
  567.   These procedures are provided by all implementations.
  568.  
  569.  - Function: identity X
  570.      IDENTITY returns its argument.
  571.  
  572.      Example:
  573.           (identity 3)
  574.              => 3
  575.           (identity '(foo bar))
  576.              => (foo bar)
  577.           (map identity LST)
  578.              == (copy-list LST)
  579.  
  580. The following procedures were present in Scheme until R4RS (*note
  581. Language changes: (r4rs)Notes.).  They are provided by all SLIB
  582. implementations.
  583.  
  584.  - Constant: t
  585.      Derfined as `#t'.
  586.  
  587.  - Constant: nil
  588.      Defined as `#f'.
  589.  
  590.  - Function: last-pair L
  591.      Returns the last pair in the list L.  Example:
  592.           (last-pair (cons 1 2))
  593.              => (1 . 2)
  594.           (last-pair '(1 2))
  595.              => (2)
  596.               == (cons 2 '())
  597.  
  598. 
  599. File: slib.info,  Node: System,  Prev: Legacy,  Up: Built-in Support
  600.  
  601. System
  602. ------
  603.  
  604. These procedures are provided by all implementations.
  605.  
  606.  - Procedure: slib:load-source NAME
  607.      Loads a file of Scheme source code from NAME with the default
  608.      filename extension used in SLIB.  For instance if the filename
  609.      extension used in SLIB is `.scm' then `(slib:load-source "foo")'
  610.      will load from file `foo.scm'.
  611.  
  612.  - Procedure: slib:load-compiled NAME
  613.      On implementations which support separtely loadable compiled
  614.      modules, loads a file of compiled code from NAME with the
  615.      implementation's filename extension for compiled code appended.
  616.  
  617.  - Procedure: slib:load NAME
  618.      Loads a file of Scheme source or compiled code from NAME with the
  619.      appropriate suffixes appended.  If both source and compiled code
  620.      are present with the appropriate names then the implementation
  621.      will load just one.  It is up to the implementation to choose
  622.      which one will be loaded.
  623.  
  624.      If an implementation does not support compiled code then
  625.      `slib:load' will be identical to `slib:load-source'.
  626.  
  627.  - Procedure: slib:eval OBJ
  628.      `eval' returns the value of OBJ evaluated in the current top level
  629.      environment.  *Note Eval:: provides a more general evaluation
  630.      facility.
  631.  
  632.  - Procedure: slib:eval-load FILENAME EVAL
  633.      FILENAME should be a string.  If filename names an existing file,
  634.      the Scheme source code expressions and definitions are read from
  635.      the file and EVAL called with them sequentially.  The
  636.      `slib:eval-load' procedure does not affect the values returned by
  637.      `current-input-port' and `current-output-port'.
  638.  
  639.  - Procedure: slib:warn ARG1 ARG2 ...
  640.      Outputs a warning message containing the arguments.
  641.  
  642.  - Procedure: slib:error ARG1 ARG2 ...
  643.      Outputs an error message containing the arguments, aborts
  644.      evaluation of the current form and responds in a system dependent
  645.      way to the error.  Typical responses are to abort the program or
  646.      to enter a read-eval-print loop.
  647.  
  648.  - Procedure: slib:exit N
  649.  - Procedure: slib:exit
  650.      Exits from the Scheme session returning status N to the system.
  651.      If N is omitted or `#t', a success status is returned to the
  652.      system (if possible).  If N is `#f' a failure is returned to the
  653.      system (if possible).  If N is an integer, then N is returned to
  654.      the system (if possible).  If the Scheme session cannot exit an
  655.      unspecified value is returned from `slib:exit'.
  656.  
  657. 
  658. File: slib.info,  Node: About this manual,  Prev: Built-in Support,  Up: The Library System
  659.  
  660. About this manual
  661. =================
  662.  
  663.    * Entries that are labeled as Functions are called for their return
  664.      values.  Entries that are labeled as Procedures are called
  665.      primarily for their side effects.
  666.  
  667.    * Examples in this text were produced using the `scm' Scheme
  668.      implementation.
  669.  
  670.    * At the beginning of each section, there is a line that looks like
  671.      `(require 'feature)'.  Include this line in your code prior to
  672.      using the package.
  673.  
  674. 
  675. File: slib.info,  Node: Scheme Syntax Extension Packages,  Next: Textual Conversion Packages,  Prev: The Library System,  Up: Top
  676.  
  677. Scheme Syntax Extension Packages
  678. ********************************
  679.  
  680. * Menu:
  681.  
  682. * Defmacro::                    Supported by all implementations
  683.  
  684. * R4RS Macros::                 'macro
  685. * Macro by Example::            'macro-by-example
  686. * Macros That Work::            'macros-that-work
  687. * Syntactic Closures::          'syntactic-closures
  688. * Syntax-Case Macros::          'syntax-case
  689.  
  690. Syntax extensions (macros) included with SLIB.  Also *Note Structures::.
  691.  
  692. * Fluid-Let::                   'fluid-let
  693. * Yasos::                       'yasos, 'oop, 'collect
  694.  
  695. 
  696. File: slib.info,  Node: Defmacro,  Next: R4RS Macros,  Prev: Scheme Syntax Extension Packages,  Up: Scheme Syntax Extension Packages
  697.  
  698. Defmacro
  699. ========
  700.  
  701.   Defmacros are supported by all implementations.
  702.  
  703.  - Function: gentemp
  704.      Returns a new (interned) symbol each time it is called.  The symbol
  705.      names are implementation-dependent
  706.           (gentemp) => scm:G0
  707.           (gentemp) => scm:G1
  708.  
  709.  - Function: defmacro:eval E
  710.      Returns the `slib:eval' of expanding all defmacros in scheme
  711.      expression E.
  712.  
  713.  - Function: defmacro:load FILENAME
  714.      FILENAME should be a string.  If filename names an existing file,
  715.      the `defmacro:load' procedure reads Scheme source code expressions
  716.      and definitions from the file and evaluates them sequentially.
  717.      These source code expressions and definitions may contain defmacro
  718.      definitions.  The `macro:load' procedure does not affect the values
  719.      returned by `current-input-port' and `current-output-port'.
  720.  
  721.  - Function: defmacro? SYM
  722.      Returns `#t' if SYM has been defined by `defmacro', `#f' otherwise.
  723.  
  724.  - Function: macroexpand-1 FORM
  725.  - Function: macroexpand FORM
  726.      If FORM is a macro call, `macroexpand-1' will expand the macro
  727.      call once and return it.  A FORM is considered to be a macro call
  728.      only if it is a cons whose `car' is a symbol for which a                 |
  729.      `defmacro' has been defined.                                             |
  730.  
  731.      `macroexpand' is similar to `macroexpand-1', but repeatedly
  732.      expands FORM until it is no longer a macro call.
  733.  
  734.  - Macro: defmacro NAME LAMBDA-LIST FORM ...
  735.      When encountered by `defmacro:eval', `defmacro:macroexpand*', or
  736.      `defmacro:load' defines a new macro which will henceforth be
  737.      expanded when encountered by `defmacro:eval',
  738.      `defmacro:macroexpand*', or `defmacro:load'.
  739.  
  740. Defmacroexpand
  741. --------------
  742.  
  743.   `(require 'defmacroexpand)'
  744.  
  745.  - Function: defmacro:expand* E
  746.      Returns the result of expanding all defmacros in scheme expression
  747.      E.
  748.  
  749. 
  750. File: slib.info,  Node: R4RS Macros,  Next: Macro by Example,  Prev: Defmacro,  Up: Scheme Syntax Extension Packages
  751.  
  752. R4RS Macros
  753. ===========
  754.  
  755.   `(require 'macro)' is the appropriate call if you want R4RS
  756. high-level macros but don't care about the low level implementation.  If
  757. an SLIB R4RS macro implementation is already loaded it will be used.
  758. Otherwise, one of the R4RS macros implemetations is loaded.
  759.  
  760.   The SLIB R4RS macro implementations support the following uniform
  761. interface:
  762.  
  763.  - Function: macro:expand SEXPRESSION
  764.      Takes an R4RS expression, macro-expands it, and returns the result
  765.      of the macro expansion.
  766.  
  767.  - Function: macro:eval SEXPRESSION
  768.      Takes an R4RS expression, macro-expands it, evals the result of the
  769.      macro expansion, and returns the result of the evaluation.
  770.  
  771.  - Procedure: macro:load FILENAME
  772.      FILENAME should be a string.  If filename names an existing file,
  773.      the `macro:load' procedure reads Scheme source code expressions and
  774.      definitions from the file and evaluates them sequentially.  These
  775.      source code expressions and definitions may contain macro
  776.      definitions.  The `macro:load' procedure does not affect the
  777.      values returned by `current-input-port' and `current-output-port'.
  778.  
  779. 
  780. File: slib.info,  Node: Macro by Example,  Next: Macros That Work,  Prev: R4RS Macros,  Up: Scheme Syntax Extension Packages
  781.  
  782. Macro by Example
  783. ================
  784.  
  785.   `(require 'macro-by-example)'
  786.  
  787.   A vanilla implementation of `Macro by Example' (Eugene Kohlbecker,
  788. R4RS) by Dorai Sitaram, (dorai@cs.rice.edu) using `defmacro'.
  789.  
  790.    * generating hygienic global `define-syntax' Macro-by-Example macros
  791.      *cheaply*.
  792.  
  793.    * can define macros which use `...'.
  794.  
  795.    * needn't worry about a lexical variable in a macro definition
  796.      clashing with a variable from the macro use context
  797.  
  798.    * don't suffer the overhead of redefining the repl if `defmacro'
  799.      natively supported (most implementations)
  800.  
  801. Caveat
  802. ------
  803.  
  804.   These macros are not referentially transparent (*note Macros:
  805. (r4rs)Macros.).  Lexically scoped macros (i.e., `let-syntax' and
  806. `letrec-syntax') are not supported.  In any case, the problem of
  807. referential transparency gains poignancy only when `let-syntax' and
  808. `letrec-syntax' are used.  So you will not be courting large-scale
  809. disaster unless you're using system-function names as local variables
  810. with unintuitive bindings that the macro can't use.  However, if you
  811. must have the full `r4rs' macro functionality, look to the more
  812. featureful (but also more expensive) versions of syntax-rules available
  813. in slib *Note Macros That Work::, *Note Syntactic Closures::, and *Note
  814. Syntax-Case Macros::.
  815.  
  816.  - Macro: define-syntax KEYWORD TRANSFORMER-SPEC
  817.      The KEYWORD is an identifier, and the TRANSFORMER-SPEC should be
  818.      an instance of `syntax-rules'.
  819.  
  820.      The top-level syntactic environment is extended by binding the
  821.      KEYWORD to the specified transformer.
  822.  
  823.           (define-syntax let*
  824.             (syntax-rules ()
  825.               ((let* () body1 body2 ...)
  826.                (let () body1 body2 ...))
  827.               ((let* ((name1 val1) (name2 val2) ...)
  828.                  body1 body2 ...)
  829.                (let ((name1 val1))
  830.                  (let* (( name2 val2) ...)
  831.                    body1 body2 ...)))))
  832.  
  833.  - Macro: syntax-rules LITERALS SYNTAX-RULE ...
  834.      LITERALS is a list of identifiers, and each SYNTAX-RULE should be
  835.      of the form
  836.  
  837.      `(PATTERN TEMPLATE)'
  838.  
  839.      where the PATTERN and  TEMPLATE are as in the grammar above.
  840.  
  841.      An instance of `syntax-rules' produces a new macro transformer by
  842.      specifying a sequence of hygienic rewrite rules.  A use of a macro
  843.      whose keyword is associated with a transformer specified by
  844.      `syntax-rules' is matched against the patterns contained in the
  845.      SYNTAX-RULEs, beginning with the leftmost SYNTAX-RULE.  When a
  846.      match is found, the macro use is trancribed hygienically according
  847.      to the template.
  848.  
  849.      Each pattern begins with the keyword for the macro.  This keyword
  850.      is not involved in the matching and is not considered a pattern
  851.      variable or literal identifier.
  852.  
  853. 
  854. File: slib.info,  Node: Macros That Work,  Next: Syntactic Closures,  Prev: Macro by Example,  Up: Scheme Syntax Extension Packages
  855.  
  856. Macros That Work
  857. ================
  858.  
  859.   `(require 'macros-that-work)'
  860.  
  861.   `Macros That Work' differs from the other R4RS macro implementations
  862. in that it does not expand derived expression types to primitive
  863. expression types.
  864.  
  865.  - Function: macro:expand EXPRESSION
  866.  - Function: macwork:expand EXPRESSION
  867.      Takes an R4RS expression, macro-expands it, and returns the result
  868.      of the macro expansion.
  869.  
  870.  - Function: macro:eval EXPRESSION
  871.  - Function: macwork:eval EXPRESSION
  872.      `macro:eval' returns the value of EXPRESSION in the current top
  873.      level environment.  EXPRESSION can contain macro definitions.
  874.      Side effects of EXPRESSION will affect the top level environment.
  875.  
  876.  - Procedure: macro:load FILENAME
  877.  - Procedure: macwork:load FILENAME
  878.      FILENAME should be a string.  If filename names an existing file,
  879.      the `macro:load' procedure reads Scheme source code expressions and
  880.      definitions from the file and evaluates them sequentially.  These
  881.      source code expressions and definitions may contain macro
  882.      definitions.  The `macro:load' procedure does not affect the
  883.      values returned by `current-input-port' and `current-output-port'.
  884.  
  885.   References:
  886.  
  887.   The `Revised^4 Report on the Algorithmic Language Scheme' Clinger and
  888. Rees [editors].  To appear in LISP Pointers.  Also available as a
  889. technical report from the University of Oregon, MIT AI Lab, and Cornell.
  890.  
  891.             Macros That Work.  Clinger and Rees.  POPL '91.
  892.  
  893.   The supported syntax differs from the R4RS in that vectors are allowed
  894. as patterns and as templates and are not allowed as pattern or template
  895. data.
  896.  
  897.      transformer spec  ==>  (syntax-rules literals rules)
  898.      
  899.      rules  ==>  ()
  900.               |  (rule . rules)
  901.      
  902.      rule  ==>  (pattern template)
  903.      
  904.      pattern  ==>  pattern_var      ; a symbol not in literals
  905.                 |  symbol           ; a symbol in literals
  906.                 |  ()
  907.                 |  (pattern . pattern)
  908.                 |  (ellipsis_pattern)
  909.                 |  #(pattern*)                     ; extends R4RS
  910.                 |  #(pattern* ellipsis_pattern)    ; extends R4RS
  911.                 |  pattern_datum
  912.      
  913.      template  ==>  pattern_var
  914.                  |  symbol
  915.                  |  ()
  916.                  |  (template2 . template2)
  917.                  |  #(template*)                   ; extends R4RS
  918.                  |  pattern_datum
  919.      
  920.      template2  ==>  template
  921.                   |  ellipsis_template
  922.      
  923.      pattern_datum  ==>  string                    ; no vector
  924.                       |  character
  925.                       |  boolean
  926.                       |  number
  927.      
  928.      ellipsis_pattern  ==> pattern ...
  929.      
  930.      ellipsis_template  ==>  template ...
  931.      
  932.      pattern_var  ==>  symbol   ; not in literals
  933.      
  934.      literals  ==>  ()
  935.                  |  (symbol . literals)
  936.  
  937. Definitions
  938. -----------
  939.  
  940. Scope of an ellipsis
  941.      Within a pattern or template, the scope of an ellipsis (`...') is
  942.      the pattern or template that appears to its left.
  943.  
  944. Rank of a pattern variable
  945.      The rank of a pattern variable is the number of ellipses within
  946.      whose scope it appears in the pattern.
  947.  
  948. Rank of a subtemplate
  949.      The rank of a subtemplate is the number of ellipses within whose
  950.      scope it appears in the template.
  951.  
  952. Template rank of an occurrence of a pattern variable
  953.      The template rank of an occurrence of a pattern variable within a
  954.      template is the rank of that occurrence, viewed as a subtemplate.
  955.  
  956. Variables bound by a pattern
  957.      The variables bound by a pattern are the pattern variables that
  958.      appear within it.
  959.  
  960. Referenced variables of a subtemplate
  961.      The referenced variables of a subtemplate are the pattern
  962.      variables that appear within it.
  963.  
  964. Variables opened by an ellipsis template
  965.      The variables opened by an ellipsis template are the referenced
  966.      pattern variables whose rank is greater than the rank of the
  967.      ellipsis template.
  968.  
  969. Restrictions
  970. ------------
  971.  
  972.   No pattern variable appears more than once within a pattern.
  973.  
  974.   For every occurrence of a pattern variable within a template, the
  975. template rank of the occurrence must be greater than or equal to the
  976. pattern variable's rank.
  977.  
  978.   Every ellipsis template must open at least one variable.
  979.  
  980.   For every ellipsis template, the variables opened by an ellipsis
  981. template must all be bound to sequences of the same length.
  982.  
  983.   The compiled form of a RULE is
  984.  
  985.      rule  ==>  (pattern template inserted)
  986.      
  987.      pattern  ==>  pattern_var
  988.                 |  symbol
  989.                 |  ()
  990.                 |  (pattern . pattern)
  991.                 |  ellipsis_pattern
  992.                 |  #(pattern)
  993.                 |  pattern_datum
  994.      
  995.      template  ==>  pattern_var
  996.                  |  symbol
  997.                  |  ()
  998.                  |  (template2 . template2)
  999.                  |  #(pattern)
  1000.                  |  pattern_datum
  1001.      
  1002.      template2  ==>  template
  1003.                   |  ellipsis_template
  1004.      
  1005.      pattern_datum  ==>  string
  1006.                       |  character
  1007.                       |  boolean
  1008.                       |  number
  1009.      
  1010.      pattern_var  ==>  #(V symbol rank)
  1011.      
  1012.      ellipsis_pattern  ==>  #(E pattern pattern_vars)
  1013.      
  1014.      ellipsis_template  ==>  #(E template pattern_vars)
  1015.      
  1016.      inserted  ==>  ()
  1017.                  |  (symbol . inserted)
  1018.      
  1019.      pattern_vars  ==>  ()
  1020.                      |  (pattern_var . pattern_vars)
  1021.      
  1022.      rank  ==>  exact non-negative integer
  1023.  
  1024.   where V and E are unforgeable values.
  1025.  
  1026.   The pattern variables associated with an ellipsis pattern are the
  1027. variables bound by the pattern, and the pattern variables associated
  1028. with an ellipsis template are the variables opened by the ellipsis
  1029. template.
  1030.  
  1031.   If the template contains a big chunk that contains no pattern
  1032. variables or inserted identifiers, then the big chunk will be copied
  1033. unnecessarily.  That shouldn't matter very often.
  1034.  
  1035. 
  1036. File: slib.info,  Node: Syntactic Closures,  Next: Syntax-Case Macros,  Prev: Macros That Work,  Up: Scheme Syntax Extension Packages
  1037.  
  1038. Syntactic Closures
  1039. ==================
  1040.  
  1041.   `(require 'syntactic-closures)'
  1042.  
  1043.  - Function: macro:expand EXPRESSION
  1044.  - Function: synclo:expand EXPRESSION
  1045.      Returns scheme code with the macros and derived expression types of
  1046.      EXPRESSION expanded to primitive expression types.
  1047.  
  1048.  - Function: macro:eval EXPRESSION
  1049.  - Function: synclo:eval EXPRESSION
  1050.      `macro:eval' returns the value of EXPRESSION in the current top
  1051.      level environment.  EXPRESSION can contain macro definitions.
  1052.      Side effects of EXPRESSION will affect the top level environment.
  1053.  
  1054.  - Procedure: macro:load FILENAME
  1055.  - Procedure: synclo:load FILENAME
  1056.      FILENAME should be a string.  If filename names an existing file,
  1057.      the `macro:load' procedure reads Scheme source code expressions and
  1058.      definitions from the file and evaluates them sequentially.  These
  1059.      source code expressions and definitions may contain macro
  1060.      definitions.  The `macro:load' procedure does not affect the
  1061.      values returned by `current-input-port' and `current-output-port'.
  1062.  
  1063. Syntactic Closure Macro Facility
  1064. --------------------------------
  1065.  
  1066.                   A Syntactic Closures Macro Facility
  1067.  
  1068.                             by Chris Hanson
  1069.  
  1070.                             9 November 1991
  1071.  
  1072.   This document describes "syntactic closures", a low-level macro
  1073. facility for the Scheme programming language.  The facility is an
  1074. alternative to the low-level macro facility described in the `Revised^4
  1075. Report on Scheme.' This document is an addendum to that report.
  1076.  
  1077.   The syntactic closures facility extends the BNF rule for TRANSFORMER
  1078. SPEC to allow a new keyword that introduces a low-level macro
  1079. transformer:
  1080.      TRANSFORMER SPEC := (transformer EXPRESSION)
  1081.  
  1082.   Additionally, the following procedures are added:
  1083.      make-syntactic-closure
  1084.      capture-syntactic-environment
  1085.      identifier?
  1086.      identifier=?
  1087.  
  1088.   The description of the facility is divided into three parts.  The
  1089. first part defines basic terminology.  The second part describes how
  1090. macro transformers are defined.  The third part describes the use of
  1091. "identifiers", which extend the syntactic closure mechanism to be
  1092. compatible with `syntax-rules'.
  1093.  
  1094. Terminology
  1095. ...........
  1096.  
  1097.   This section defines the concepts and data types used by the syntactic
  1098. closures facility.
  1099.  
  1100.    * "Forms" are the syntactic entities out of which programs are
  1101.      recursively constructed.  A form is any expression, any
  1102.      definition, any syntactic keyword, or any syntactic closure.  The
  1103.      variable name that appears in a `set!' special form is also a
  1104.      form.  Examples of forms:
  1105.           17
  1106.           #t
  1107.           car
  1108.           (+ x 4)
  1109.           (lambda (x) x)
  1110.           (define pi 3.14159)
  1111.           if
  1112.           define
  1113.  
  1114.    * An "alias" is an alternate name for a given symbol.  It can appear
  1115.      anywhere in a form that the symbol could be used, and when quoted
  1116.      it is replaced by the symbol; however, it does not satisfy the
  1117.      predicate `symbol?'.  Macro transformers rarely distinguish
  1118.      symbols from aliases, referring to both as identifiers.
  1119.  
  1120.    * A "syntactic" environment maps identifiers to their meanings.
  1121.      More precisely, it determines whether an identifier is a syntactic
  1122.      keyword or a variable.  If it is a keyword, the meaning is an
  1123.      interpretation for the form in which that keyword appears.  If it
  1124.      is a variable, the meaning identifies which binding of that
  1125.      variable is referenced.  In short, syntactic environments contain
  1126.      all of the contextual information necessary for interpreting the
  1127.      meaning of a particular form.
  1128.  
  1129.    * A "syntactic closure" consists of a form, a syntactic environment,
  1130.      and a list of identifiers.  All identifiers in the form take their
  1131.      meaning from the syntactic environment, except those in the given
  1132.      list.  The identifiers in the list are to have their meanings
  1133.      determined later.  A syntactic closure may be used in any context
  1134.      in which its form could have been used.  Since a syntactic closure
  1135.      is also a form, it may not be used in contexts where a form would
  1136.      be illegal.  For example, a form may not appear as a clause in the
  1137.      cond special form.  A syntactic closure appearing in a quoted
  1138.      structure is replaced by its form.
  1139.  
  1140. Transformer Definition
  1141. ......................
  1142.  
  1143.   This section describes the `transformer' special form and the
  1144. procedures `make-syntactic-closure' and `capture-syntactic-environment'.
  1145.  
  1146.  - Syntax: transformer EXPRESSION
  1147.      Syntax: It is an error if this syntax occurs except as a
  1148.      TRANSFORMER SPEC.
  1149.  
  1150.      Semantics: The EXPRESSION is evaluated in the standard transformer
  1151.      environment to yield a macro transformer as described below.  This
  1152.      macro transformer is bound to a macro keyword by the special form
  1153.      in which the `transformer' expression appears (for example,
  1154.      `let-syntax').
  1155.  
  1156.      A "macro transformer" is a procedure that takes two arguments, a
  1157.      form and a syntactic environment, and returns a new form.  The
  1158.      first argument, the "input form", is the form in which the macro
  1159.      keyword occurred.  The second argument, the "usage environment",
  1160.      is the syntactic environment in which the input form occurred.
  1161.      The result of the transformer, the "output form", is automatically
  1162.      closed in the "transformer environment", which is the syntactic
  1163.      environment in which the `transformer' expression occurred.
  1164.  
  1165.      For example, here is a definition of a push macro using
  1166.      `syntax-rules':
  1167.           (define-syntax  push
  1168.             (syntax-rules ()
  1169.               ((push item list)
  1170.                (set! list (cons item list)))))
  1171.  
  1172.      Here is an equivalent definition using `transformer':
  1173.           (define-syntax push
  1174.             (transformer
  1175.              (lambda (exp env)
  1176.                (let ((item
  1177.                       (make-syntactic-closure env '() (cadr exp)))
  1178.                      (list
  1179.                       (make-syntactic-closure env '() (caddr exp))))
  1180.                  `(set! ,list (cons ,item ,list))))))
  1181.  
  1182.      In this example, the identifiers `set!' and `cons' are closed in
  1183.      the transformer environment, and thus will not be affected by the
  1184.      meanings of those identifiers in the usage environment `env'.
  1185.  
  1186.      Some macros may be non-hygienic by design.  For example, the
  1187.      following defines a loop macro that implicitly binds `exit' to an
  1188.      escape procedure.  The binding of `exit' is intended to capture
  1189.      free references to `exit' in the body of the loop, so `exit' must
  1190.      be left free when the body is closed:
  1191.           (define-syntax loop
  1192.             (transformer
  1193.              (lambda (exp env)
  1194.                (let ((body (cdr exp)))
  1195.                  `(call-with-current-continuation
  1196.                    (lambda (exit)
  1197.                      (let f ()
  1198.                        ,@(map (lambda  (exp)
  1199.                                  (make-syntactic-closure env '(exit)
  1200.                                                          exp))
  1201.                                body)
  1202.                        (f))))))))
  1203.  
  1204.      To assign meanings to the identifiers in a form, use
  1205.      `make-syntactic-closure' to close the form in a syntactic
  1206.      environment.
  1207.  
  1208.  - Function: make-syntactic-closure ENVIRONMENT FREE-NAMES FORM
  1209.      ENVIRONMENT must be a syntactic environment, FREE-NAMES must be a
  1210.      list of identifiers, and FORM must be a form.
  1211.      `make-syntactic-closure' constructs and returns a syntactic closure
  1212.      of FORM in ENVIRONMENT, which can be used anywhere that FORM could
  1213.      have been used.  All the identifiers used in FORM, except those
  1214.      explicitly excepted by FREE-NAMES, obtain their meanings from
  1215.      ENVIRONMENT.
  1216.  
  1217.      Here is an example where FREE-NAMES is something other than the
  1218.      empty list.  It is instructive to compare the use of FREE-NAMES in
  1219.      this example with its use in the `loop' example above: the examples
  1220.      are similar except for the source of the identifier being left
  1221.      free.
  1222.           (define-syntax let1
  1223.             (transformer
  1224.              (lambda (exp env)
  1225.                (let ((id (cadr exp))
  1226.                      (init (caddr exp))
  1227.                      (exp (cadddr exp)))
  1228.                  `((lambda (,id)
  1229.                      ,(make-syntactic-closure env (list id) exp))
  1230.                    ,(make-syntactic-closure env '() init))))))
  1231.  
  1232.      `let1' is a simplified version of `let' that only binds a single
  1233.      identifier, and whose body consists of a single expression.  When
  1234.      the body expression is syntactically closed in its original
  1235.      syntactic environment, the identifier that is to be bound by
  1236.      `let1' must be left free, so that it can be properly captured by
  1237.      the `lambda' in the output form.
  1238.  
  1239.      To obtain a syntactic environment other than the usage
  1240.      environment, use `capture-syntactic-environment'.
  1241.  
  1242.  - Function: capture-syntactic-environment PROCEDURE
  1243.      `capture-syntactic-environment' returns a form that will, when
  1244.      transformed, call PROCEDURE on the current syntactic environment.
  1245.      PROCEDURE should compute and return a new form to be transformed,
  1246.      in that same syntactic environment, in place of the form.
  1247.  
  1248.      An example will make this clear.  Suppose we wanted to define a
  1249.      simple `loop-until' keyword equivalent to
  1250.           (define-syntax loop-until
  1251.             (syntax-rules ()
  1252.               ((loop-until id init test return step)
  1253.                (letrec ((loop
  1254.                          (lambda (id)
  1255.                            (if test return (loop step)))))
  1256.                  (loop init)))))
  1257.  
  1258.      The following attempt at defining `loop-until' has a subtle bug:
  1259.           (define-syntax loop-until
  1260.             (transformer
  1261.              (lambda (exp env)
  1262.                (let ((id (cadr exp))
  1263.                      (init (caddr exp))
  1264.                      (test (cadddr exp))
  1265.                      (return (cadddr (cdr exp)))
  1266.                      (step (cadddr (cddr exp)))
  1267.                      (close
  1268.                       (lambda (exp free)
  1269.                         (make-syntactic-closure env free exp))))
  1270.                  `(letrec ((loop
  1271.                             (lambda (,id)
  1272.                               (if ,(close test (list id))
  1273.                                   ,(close return (list id))
  1274.                                   (loop ,(close step (list id)))))))
  1275.                     (loop ,(close init '())))))))
  1276.  
  1277.      This definition appears to take all of the proper precautions to
  1278.      prevent unintended captures.  It carefully closes the
  1279.      subexpressions in their original syntactic environment and it
  1280.      leaves the `id' identifier free in the `test', `return', and
  1281.      `step' expressions, so that it will be captured by the binding
  1282.      introduced by the `lambda' expression.  Unfortunately it uses the
  1283.      identifiers `if' and `loop' within that `lambda' expression, so if
  1284.      the user of `loop-until' just happens to use, say, `if' for the
  1285.      identifier, it will be inadvertently captured.
  1286.  
  1287.      The syntactic environment that `if' and `loop' want to be exposed
  1288.      to is the one just outside the `lambda' expression: before the
  1289.      user's identifier is added to the syntactic environment, but after
  1290.      the identifier loop has been added.
  1291.      `capture-syntactic-environment' captures exactly that environment
  1292.      as follows:
  1293.           (define-syntax loop-until
  1294.             (transformer
  1295.              (lambda (exp env)
  1296.                (let ((id (cadr exp))
  1297.                      (init (caddr exp))
  1298.                      (test (cadddr exp))
  1299.                      (return (cadddr (cdr exp)))
  1300.                      (step (cadddr (cddr exp)))
  1301.                      (close
  1302.                       (lambda (exp free)
  1303.                         (make-syntactic-closure env free exp))))
  1304.                  `(letrec ((loop
  1305.                             ,(capture-syntactic-environment
  1306.                               (lambda (env)
  1307.                                 `(lambda (,id)
  1308.                                    (,(make-syntactic-closure env '() `if)
  1309.                                     ,(close test (list id))
  1310.                                     ,(close return (list id))
  1311.                                     (,(make-syntactic-closure env '()
  1312.                                                               `loop)
  1313.                                      ,(close step (list id)))))))))
  1314.                     (loop ,(close init '())))))))
  1315.  
  1316.      In this case, having captured the desired syntactic environment,
  1317.      it is convenient to construct syntactic closures of the
  1318.      identifiers `if' and the `loop' and use them in the body of the
  1319.      `lambda'.
  1320.  
  1321.      A common use of `capture-syntactic-environment' is to get the
  1322.      transformer environment of a macro transformer:
  1323.           (transformer
  1324.            (lambda (exp env)
  1325.              (capture-syntactic-environment
  1326.               (lambda (transformer-env)
  1327.                 ...))))
  1328.  
  1329. Identifiers
  1330. ...........
  1331.  
  1332.   This section describes the procedures that create and manipulate
  1333. identifiers.  Previous syntactic closure proposals did not have an
  1334. identifier data type - they just used symbols.  The identifier data
  1335. type extends the syntactic closures facility to be compatible with the
  1336. high-level `syntax-rules' facility.
  1337.  
  1338.   As discussed earlier, an identifier is either a symbol or an "alias".
  1339. An alias is implemented as a syntactic closure whose "form" is an
  1340. identifier:
  1341.      (make-syntactic-closure env '() 'a)
  1342.         => an "alias"
  1343.  
  1344.   Aliases are implemented as syntactic closures because they behave just
  1345. like syntactic closures most of the time.  The difference is that an
  1346. alias may be bound to a new value (for example by `lambda' or
  1347. `let-syntax'); other syntactic closures may not be used this way.  If
  1348. an alias is bound, then within the scope of that binding it is looked
  1349. up in the syntactic environment just like any other identifier.
  1350.  
  1351.   Aliases are used in the implementation of the high-level facility
  1352. `syntax-rules'.  A macro transformer created by `syntax-rules' uses a
  1353. template to generate its output form, substituting subforms of the
  1354. input form into the template.  In a syntactic closures implementation,
  1355. all of the symbols in the template are replaced by aliases closed in
  1356. the transformer environment, while the output form itself is closed in
  1357. the usage environment.  This guarantees that the macro transformation
  1358. is hygienic, without requiring the transformer to know the syntactic
  1359. roles of the substituted input subforms.
  1360.  
  1361.  - Function: identifier? OBJECT
  1362.      Returns `#t' if OBJECT is an identifier, otherwise returns `#f'.
  1363.      Examples:
  1364.           (identifier? 'a)
  1365.              => #t
  1366.           (identifier? (make-syntactic-closure env '() 'a))
  1367.              => #t
  1368.           (identifier? "a")
  1369.              => #f
  1370.           (identifier? #\a)
  1371.              => #f
  1372.           (identifier? 97)
  1373.              => #f
  1374.           (identifier? #f)
  1375.              => #f
  1376.           (identifier? '(a))
  1377.              => #f
  1378.           (identifier? '#(a))
  1379.              => #f
  1380.  
  1381.      The predicate `eq?' is used to determine if two identifers are
  1382.      "the same".  Thus `eq?' can be used to compare identifiers exactly
  1383.      as it would be used to compare symbols.  Often, though, it is
  1384.      useful to know whether two identifiers "mean the same thing".  For
  1385.      example, the `cond' macro uses the symbol `else' to identify the
  1386.      final clause in the conditional.  A macro transformer for `cond'
  1387.      cannot just look for the symbol `else', because the `cond' form
  1388.      might be the output of another macro transformer that replaced the
  1389.      symbol `else' with an alias.  Instead the transformer must look
  1390.      for an identifier that "means the same thing" in the usage
  1391.      environment as the symbol `else' means in the transformer
  1392.      environment.
  1393.  
  1394.  - Function: identifier=? ENVIRONMENT1 IDENTIFIER1 ENVIRONMENT2
  1395.           IDENTIFIER2
  1396.      ENVIRONMENT1 and ENVIRONMENT2 must be syntactic environments, and
  1397.      IDENTIFIER1 and IDENTIFIER2 must be identifiers.  `identifier=?'
  1398.      returns `#t' if the meaning of IDENTIFIER1 in ENVIRONMENT1 is the
  1399.      same as that of IDENTIFIER2 in ENVIRONMENT2, otherwise it returns
  1400.      `#f'.  Examples:
  1401.  
  1402.           (let-syntax
  1403.               ((foo
  1404.                 (transformer
  1405.                  (lambda (form env)
  1406.                    (capture-syntactic-environment
  1407.                     (lambda (transformer-env)
  1408.                       (identifier=? transformer-env 'x env 'x)))))))
  1409.             (list (foo)
  1410.                   (let ((x 3))
  1411.                     (foo))))
  1412.              => (#t #f)
  1413.  
  1414.           (let-syntax ((bar foo))
  1415.             (let-syntax
  1416.                 ((foo
  1417.                   (transformer
  1418.                    (lambda (form env)
  1419.                      (capture-syntactic-environment
  1420.                       (lambda (transformer-env)
  1421.                         (identifier=? transformer-env 'foo
  1422.                                       env (cadr form))))))))
  1423.               (list (foo foo)
  1424.                     (foobar))))
  1425.              => (#f #t)
  1426.  
  1427. Acknowledgements
  1428. ................
  1429.  
  1430.   The syntactic closures facility was invented by Alan Bawden and
  1431. Jonathan Rees.  The use of aliases to implement `syntax-rules' was
  1432. invented by Alan Bawden (who prefers to call them "synthetic names").
  1433. Much of this proposal is derived from an earlier proposal by Alan
  1434. Bawden.
  1435.  
  1436. 
  1437. File: slib.info,  Node: Syntax-Case Macros,  Next: Fluid-Let,  Prev: Syntactic Closures,  Up: Scheme Syntax Extension Packages
  1438.  
  1439. Syntax-Case Macros
  1440. ==================
  1441.  
  1442.   `(require 'syntax-case)'
  1443.  
  1444.  - Function: macro:expand EXPRESSION
  1445.  - Function: syncase:expand EXPRESSION
  1446.      Returns scheme code with the macros and derived expression types of
  1447.      EXPRESSION expanded to primitive expression types.
  1448.  
  1449.  - Function: macro:eval EXPRESSION
  1450.  - Function: syncase:eval EXPRESSION
  1451.      `macro:eval' returns the value of EXPRESSION in the current top
  1452.      level environment.  EXPRESSION can contain macro definitions.
  1453.      Side effects of EXPRESSION will affect the top level environment.
  1454.  
  1455.  - Procedure: macro:load FILENAME
  1456.  - Procedure: syncase:load FILENAME
  1457.      FILENAME should be a string.  If filename names an existing file,
  1458.      the `macro:load' procedure reads Scheme source code expressions and
  1459.      definitions from the file and evaluates them sequentially.  These
  1460.      source code expressions and definitions may contain macro
  1461.      definitions.  The `macro:load' procedure does not affect the
  1462.      values returned by `current-input-port' and `current-output-port'.
  1463.  
  1464.   This is version 2.1 of `syntax-case', the low-level macro facility
  1465. proposed and implemented by Robert Hieb and R. Kent Dybvig.
  1466.  
  1467.   This version is further adapted by Harald Hanche-Olsen
  1468. <hanche@imf.unit.no> to make it compatible with, and easily usable
  1469. with, SLIB.  Mainly, these adaptations consisted of:
  1470.  
  1471.    * Removing white space from `expand.pp' to save space in the
  1472.      distribution.  This file is not meant for human readers anyway...
  1473.  
  1474.    * Removed a couple of Chez scheme dependencies.
  1475.  
  1476.    * Renamed global variables used to minimize the possibility of name
  1477.      conflicts.
  1478.  
  1479.    * Adding an SLIB-specific initialization file.
  1480.  
  1481.    * Removing a couple extra files, most notably the documentation (but
  1482.      see below).
  1483.  
  1484.   If you wish, you can see exactly what changes were done by reading the
  1485. shell script in the file `syncase.sh'.
  1486.  
  1487.   The two PostScript files were omitted in order to not burden the SLIB
  1488. distribution with them.  If you do intend to use `syntax-case',
  1489. however, you should get these files and print them out on a PostScript
  1490. printer.  They are available with the original `syntax-case'
  1491. distribution by anonymous FTP in
  1492. `cs.indiana.edu:/pub/scheme/syntax-case'.
  1493.  
  1494.   In order to use syntax-case from an interactive top level, execute:
  1495.      (require 'syntax-case)
  1496.      (require 'repl)
  1497.      (repl:top-level macro:eval)
  1498.   See the section Repl (*note Repl::.) for more information.
  1499.  
  1500.   To check operation of syntax-case get
  1501. `cs.indiana.edu:/pub/scheme/syntax-case', and type
  1502.      (require 'syntax-case)
  1503.      (syncase:sanity-check)
  1504.  
  1505.   Beware that `syntax-case' takes a long time to load - about 20s on a
  1506. SPARCstation SLC (with SCM) and about 90s on a Macintosh SE/30 (with
  1507. Gambit).
  1508.  
  1509. Notes
  1510. -----
  1511.  
  1512.   All R4RS syntactic forms are defined, including `delay'.  Along with
  1513. `delay' are simple definitions for `make-promise' (into which `delay'
  1514. expressions expand) and `force'.
  1515.  
  1516.   `syntax-rules' and `with-syntax' (described in `TR356') are defined.
  1517.  
  1518.   `syntax-case' is actually defined as a macro that expands into calls
  1519. to the procedure `syntax-dispatch' and the core form `syntax-lambda';
  1520. do not redefine these names.
  1521.  
  1522.   Several other top-level bindings not documented in TR356 are created:
  1523.    * the "hooks" in `hooks.ss'
  1524.  
  1525.    * the `build-' procedures in `output.ss'
  1526.  
  1527.    * `expand-syntax' (the expander)
  1528.  
  1529.   The syntax of define has been extended to allow `(define ID)', which
  1530. assigns ID to some unspecified value.
  1531.  
  1532.   We have attempted to maintain R4RS compatibility where possible.  The
  1533. incompatibilities should be confined to `hooks.ss'.  Please let us know
  1534. if there is some incompatibility that is not flagged as such.
  1535.  
  1536.   Send bug reports, comments, suggestions, and questions to Kent Dybvig
  1537. (dyb@iuvax.cs.indiana.edu).
  1538.  
  1539. Note from maintainer
  1540. --------------------
  1541.  
  1542.   Included with the `syntax-case' files was `structure.scm' which
  1543. defines a macro `define-structure'.  There is no documentation for this
  1544. macro and it is not used by any code in SLIB.
  1545.  
  1546. 
  1547. File: slib.info,  Node: Fluid-Let,  Next: Yasos,  Prev: Syntax-Case Macros,  Up: Scheme Syntax Extension Packages
  1548.  
  1549. Fluid-Let
  1550. =========
  1551.  
  1552.   `(require 'fluid-let)'
  1553.  
  1554.  - Syntax: fluid-let `(BINDINGS ...)' FORMS...
  1555.  
  1556.      (fluid-let ((VARIABLE INIT) ...)
  1557.         EXPRESSION EXPRESSION ...)
  1558.  
  1559.   The INITs are evaluated in the current environment (in some
  1560. unspecified order), the current values of the VARIABLEs are saved, the
  1561. results are assigned to the VARIABLEs, the EXPRESSIONs are evaluated
  1562. sequentially in the current environment, the VARIABLEs are restored to
  1563. their original values, and the value of the last EXPRESSION is returned.
  1564.  
  1565.   The syntax of this special form is similar to that of `let', but
  1566. `fluid-let' temporarily rebinds existing VARIABLEs.  Unlike `let',
  1567. `fluid-let' creates no new bindings; instead it *assigns* the values of
  1568. each INIT to the binding (determined by the rules of lexical scoping)
  1569. of its corresponding VARIABLE.
  1570.  
  1571. 
  1572. File: slib.info,  Node: Yasos,  Prev: Fluid-Let,  Up: Scheme Syntax Extension Packages
  1573.  
  1574. Yasos
  1575. =====
  1576.  
  1577.   `(require 'oop)' or `(require 'yasos)'
  1578.  
  1579.   `Yet Another Scheme Object System' is a simple object system for
  1580. Scheme based on the paper by Norman Adams and Jonathan Rees: `Object
  1581. Oriented Programming in Scheme', Proceedings of the 1988 ACM Conference
  1582. on LISP and Functional Programming, July 1988 [ACM #552880].
  1583.  
  1584.   Another reference is:
  1585.  
  1586.   Ken Dickey.  Scheming with Objects `AI Expert' Volume 7, Number 10
  1587. (October 1992), pp. 24-33.
  1588.  
  1589. * Menu:
  1590.  
  1591. * Yasos terms::                 Definitions and disclaimer.
  1592. * Yasos interface::             The Yasos macros and procedures.
  1593. * Setters::                     Dylan-like setters in Yasos.
  1594. * Yasos examples::              Usage of Yasos and setters.
  1595.  
  1596. 
  1597. File: slib.info,  Node: Yasos terms,  Next: Yasos interface,  Prev: Yasos,  Up: Yasos
  1598.  
  1599. Terms
  1600. -----
  1601.  
  1602. "Object"
  1603.      Any Scheme data object.
  1604.  
  1605. "Instance"
  1606.      An instance of the OO system; an "object".
  1607.  
  1608. "Operation"
  1609.      A METHOD.
  1610.  
  1611. *Notes:*
  1612.      The object system supports multiple inheritance.  An instance can
  1613.      inherit from 0 or more ancestors.  In the case of multiple
  1614.      inherited operations with the same identity, the operation used is
  1615.      that from the first ancestor which contains it (in the ancestor
  1616.      `let').  An operation may be applied to any Scheme data
  1617.      object--not just instances.  As code which creates instances is
  1618.      just code, there are no "classes" and no meta-ANYTHING.  Method
  1619.      dispatch is by a procedure call a la CLOS rather than by `send'
  1620.      syntax a la Smalltalk.
  1621.  
  1622. *Disclaimer:*
  1623.      There are a number of optimizations which can be made.  This
  1624.      implementation is expository (although performance should be quite
  1625.      reasonable).  See the L&FP paper for some suggestions.
  1626.  
  1627. 
  1628. File: slib.info,  Node: Yasos interface,  Next: Setters,  Prev: Yasos terms,  Up: Yasos
  1629.  
  1630. Interface
  1631. ---------
  1632.  
  1633.  - Syntax: define-operation `('OPNAME SELF ARG ...`)' DEFAULT-BODY
  1634.      Defines a default behavior for data objects which don't handle the
  1635.      operation OPNAME.  The default behavior (for an empty
  1636.      DEFAULT-BODY) is to generate an error.
  1637.  
  1638.  - Syntax: define-predicate OPNAME?
  1639.      Defines a predicate OPNAME?, usually used for determining the
  1640.      "type" of an object, such that `(OPNAME? OBJECT)' returns `#t' if
  1641.      OBJECT has an operation OPNAME? and `#f' otherwise.
  1642.  
  1643.  - Syntax: object `((NAME SELF ARG ...) BODY)' ...
  1644.      Returns an object (an instance of the object system) with
  1645.      operations.  Invoking `(NAME OBJECT ARG ...' executes the BODY of
  1646.      the OBJECT with SELF bound to OBJECT and with argument(s) ARG....
  1647.  
  1648.  - Syntax: object-with-ancestors `(('ANCESTOR1 INIT1`)' ...`)'
  1649.           OPERATION ...
  1650.      A `let'-like form of `object' for multiple inheritance.  It
  1651.      returns an object inheriting the behaviour of ANCESTOR1 etc.  An
  1652.      operation will be invoked in an ancestor if the object itself does
  1653.      not provide such a method.  In the case of multiple inherited
  1654.      operations with the same identity, the operation used is the one
  1655.      found in the first ancestor in the ancestor list.
  1656.  
  1657.  - Syntax: operate-as COMPONENT OPERATION SELF ARG ...
  1658.      Used in an operation definition (of SELF) to invoke the OPERATION
  1659.      in an ancestor COMPONENT but maintain the object's identity.  Also
  1660.      known as "send-to-super".
  1661.  
  1662.  - Procedure: print OBJ PORT
  1663.      A default `print' operation is provided which is just `(format
  1664.      PORT OBJ)' (*note Format::.) for non-instances and prints OBJ
  1665.      preceded by `#<INSTANCE>' for instances.
  1666.  
  1667.  - Function: size OBJ
  1668.      The default method returns the number of elements in OBJ if it is
  1669.      a vector, string or list, `2' for a pair, `1' for a character and
  1670.      by default id an error otherwise.  Objects such as collections
  1671.      (*note Collections::.) may override the default in an obvious way.
  1672.  
  1673. 
  1674. File: slib.info,  Node: Setters,  Next: Yasos examples,  Prev: Yasos interface,  Up: Yasos
  1675.  
  1676. Setters
  1677. -------
  1678.  
  1679.   "Setters" implement "generalized locations" for objects associated
  1680. with some sort of mutable state.  A "getter" operation retrieves a
  1681. value from a generalized location and the corresponding setter
  1682. operation stores a value into the location.  Only the getter is named -
  1683. the setter is specified by a procedure call as below.  (Dylan uses
  1684. special syntax.)  Typically, but not necessarily, getters are access
  1685. operations to extract values from Yasos objects (*note Yasos::.).
  1686. Several setters are predefined, corresponding to getters `car', `cdr',
  1687. `string-ref' and `vector-ref' e.g., `(setter car)' is equivalent to
  1688. `set-car!'.
  1689.  
  1690.   This implementation of setters is similar to that in Dylan(TM)
  1691. (`Dylan: An object-oriented dynamic language', Apple Computer Eastern
  1692. Research and Technology).  Common LISP provides similar facilities
  1693. through `setf'.
  1694.  
  1695.  - Function: setter GETTER
  1696.      Returns the setter for the procedure GETTER.  E.g., since
  1697.      `string-ref' is the getter corresponding to a setter which is
  1698.      actually `string-set!':
  1699.           (define foo "foo")
  1700.           ((setter string-ref) foo 0 #\F) ; set element 0 of foo
  1701.           foo => "Foo"
  1702.  
  1703.  - Syntax: set PLACE NEW-VALUE
  1704.      If PLACE is a variable name, `set' is equivalent to `set!'.
  1705.      Otherwise, PLACE must have the form of a procedure call, where the
  1706.      procedure name refers to a getter and the call indicates an
  1707.      accessible generalized location, i.e., the call would return a
  1708.      value.  The return value of `set' is usually unspecified unless
  1709.      used with a setter whose definition guarantees to return a useful
  1710.      value.
  1711.           (set (string-ref foo 2) #\O)  ; generalized location with getter
  1712.           foo => "FoO"
  1713.           (set foo "foo")               ; like set!
  1714.           foo => "foo"
  1715.  
  1716.  - Procedure: add-setter GETTER SETTER
  1717.      Add procedures GETTER and SETTER to the (inaccessible) list of
  1718.      valid setter/getter pairs.  SETTER implements the store operation
  1719.      corresponding to the GETTER access operation for the relevant
  1720.      state.  The return value is unspecified.
  1721.  
  1722.  - Procedure: remove-setter-for GETTER
  1723.      Removes the setter corresponding to the specified GETTER from the
  1724.      list of valid setters.  The return value is unspecified.
  1725.  
  1726.  - Syntax: define-access-operation GETTER-NAME
  1727.      Shorthand for a Yasos `define-operation' defining an operation
  1728.      GETTER-NAME that objects may support to return the value of some
  1729.      mutable state.  The default operation is to signal an error.  The
  1730.      return value is unspecified.
  1731.  
  1732. 
  1733. File: slib.info,  Node: Yasos examples,  Prev: Setters,  Up: Yasos
  1734.  
  1735. Examples
  1736. --------
  1737.  
  1738.      ;;; These definitions for PRINT and SIZE are
  1739.      ;;; already supplied by
  1740.      (require 'yasos)
  1741.      
  1742.      (define-operation (print obj port)
  1743.        (format port
  1744.                (if (instance? obj) "#<instance>" "~s")
  1745.                obj))
  1746.      
  1747.      (define-operation (size obj)
  1748.        (cond
  1749.         ((vector? obj) (vector-length obj))
  1750.         ((list?   obj) (length obj))
  1751.         ((pair?   obj) 2)
  1752.         ((string? obj) (string-length obj))
  1753.         ((char?   obj) 1)
  1754.         (else
  1755.          (error "Operation not supported: size" obj))))
  1756.      
  1757.      (define-predicate cell?)
  1758.      (define-operation (fetch obj))
  1759.      (define-operation (store! obj newValue))
  1760.      
  1761.      (define (make-cell value)
  1762.        (object
  1763.         ((cell? self) #t)
  1764.         ((fetch self) value)
  1765.         ((store! self newValue)
  1766.          (set! value newValue)
  1767.          newValue)
  1768.         ((size self) 1)
  1769.         ((print self port)
  1770.          (format port "#<Cell: ~s>" (fetch self)))))
  1771.      
  1772.      (define-operation (discard obj value)
  1773.        (format #t "Discarding ~s~%" value))
  1774.      
  1775.      (define (make-filtered-cell value filter)
  1776.        (object-with-ancestors
  1777.         ((cell (make-cell value)))
  1778.         ((store! self newValue)
  1779.         (if (filter newValue)
  1780.             (store! cell newValue)
  1781.             (discard self newValue)))))
  1782.      
  1783.      (define-predicate array?)
  1784.      (define-operation (array-ref array index))
  1785.      (define-operation (array-set! array index value))
  1786.      
  1787.      (define (make-array num-slots)
  1788.        (let ((anArray (make-vector num-slots)))
  1789.          (object
  1790.           ((array? self) #t)
  1791.           ((size self) num-slots)
  1792.           ((array-ref self index)
  1793.            (vector-ref  anArray index))
  1794.           ((array-set! self index newValue)
  1795.            (vector-set! anArray index newValue))
  1796.           ((print self port)
  1797.            (format port "#<Array ~s>" (size self))))))
  1798.      
  1799.      (define-operation (position obj))
  1800.      (define-operation (discarded-value obj))
  1801.      
  1802.      (define (make-cell-with-history value filter size)
  1803.        (let ((pos 0) (most-recent-discard #f))
  1804.          (object-with-ancestors
  1805.           ((cell (make-filtered-call value filter))
  1806.            (sequence (make-array size)))
  1807.           ((array? self) #f)
  1808.           ((position self) pos)
  1809.           ((store! self newValue)
  1810.            (operate-as cell store! self newValue)
  1811.            (array-set! self pos newValue)
  1812.            (set! pos (+ pos 1)))
  1813.           ((discard self value)
  1814.            (set! most-recent-discard value))
  1815.           ((discarded-value self) most-recent-discard)
  1816.           ((print self port)
  1817.            (format port "#<Cell-with-history ~s>"
  1818.                    (fetch self))))))
  1819.      
  1820.      (define-access-operation fetch)
  1821.      (add-setter fetch store!)
  1822.      (define foo (make-cell 1))
  1823.      (print foo #f)
  1824.      => "#<Cell: 1>"
  1825.      (set (fetch foo) 2)
  1826.      =>
  1827.      (print foo #f)
  1828.      => "#<Cell: 2>"
  1829.      (fetch foo)
  1830.      => 2
  1831.  
  1832. 
  1833. File: slib.info,  Node: Textual Conversion Packages,  Next: Mathematical Packages,  Prev: Scheme Syntax Extension Packages,  Up: Top
  1834.  
  1835. Textual Conversion Packages
  1836. ***************************
  1837.  
  1838. * Menu:
  1839.  
  1840. * Precedence Parsing::
  1841. * Format::                      Common-Lisp Format
  1842. * Standard Formatted I/O::      Posix printf and scanf
  1843. * Programs and Arguments::
  1844. * HTML HTTP and CGI::           Generate pages and serve WWW sites
  1845. * Printing Scheme::             Nicely
  1846. * Time and Date::
  1847. * Vector Graphics::
  1848. * Schmooz::                     Documentation markup for Scheme programs
  1849.  
  1850. 
  1851. File: slib.info,  Node: Precedence Parsing,  Next: Format,  Prev: Textual Conversion Packages,  Up: Textual Conversion Packages
  1852.  
  1853. Precedence Parsing
  1854. ==================
  1855.  
  1856.   `(require 'precedence-parse)' or `(require 'parse)'
  1857.  
  1858. This package implements:
  1859.  
  1860.    * a Pratt style precedence parser;
  1861.  
  1862.    * a "tokenizer" which congeals tokens according to assigned classes
  1863.      of constituent characters;
  1864.  
  1865.    * procedures giving direct control of parser rulesets;
  1866.  
  1867.    * procedures for higher level specification of rulesets.
  1868.  
  1869. * Menu:
  1870.  
  1871. * Precedence Parsing Overview::
  1872. * Ruleset Definition and Use::
  1873. * Token definition::
  1874. * Nud and Led Definition::
  1875. * Grammar Rule Definition::
  1876.  
  1877. 
  1878. File: slib.info,  Node: Precedence Parsing Overview,  Next: Ruleset Definition and Use,  Prev: Precedence Parsing,  Up: Precedence Parsing
  1879.  
  1880. Precedence Parsing Overview
  1881. ---------------------------
  1882.  
  1883. This package offers improvements over previous parsers.
  1884.  
  1885.    * Common computer language constructs are concisely specified.
  1886.  
  1887.    * Grammars can be changed dynamically.  Operators can be assigned
  1888.      different meanings within a lexical context.
  1889.  
  1890.    * Rulesets don't need compilation.  Grammars can be changed
  1891.      incrementally.
  1892.  
  1893.    * Operator precedence is specified by integers.
  1894.  
  1895.    * All possibilities of bad input are handled (1) and return as much
  1896.      structure as was parsed when the error occured; The symbol `?' is
  1897.      substituted for missing input.
  1898.  
  1899. Here are the higher-level syntax types and an example of each.
  1900. Precedence considerations are omitted for clarity.  See *Note Grammar
  1901. Rule Definition:: for full details.
  1902.  
  1903.  - Grammar: nofix bye exit
  1904.           bye
  1905.      calls the function `exit' with no arguments.
  1906.  
  1907.  - Grammar: prefix - negate
  1908.           - 42
  1909.      Calls the function `negate' with the argument `42'.
  1910.  
  1911.  - Grammar: infix - difference
  1912.           x - y
  1913.      Calls the function `difference' with arguments `x' and `y'.
  1914.  
  1915.  - Grammar: nary + sum
  1916.           x + y + z
  1917.      Calls the function `sum' with arguments `x', `y', and `y'.
  1918.  
  1919.  - Grammar: postfix ! factorial
  1920.           5 !
  1921.      Calls the function `factorial' with the argument `5'.
  1922.  
  1923.  - Grammar: prestfix set set!
  1924.           set foo bar
  1925.      Calls the function `set!' with the arguments `foo' and `bar'.
  1926.  
  1927.  - Grammar: commentfix /* */
  1928.           /* almost any text here */
  1929.      Ignores the comment delimited by `/*' and `*/'.
  1930.  
  1931.  - Grammar: matchfix { list }
  1932.           {0, 1, 2}
  1933.      Calls the function `list' with the arguments `0', `1', and `2'.
  1934.  
  1935.  - Grammar: inmatchfix ( funcall )
  1936.           f(x, y)
  1937.      Calls the function `funcall' with the arguments `f', `x', and `y'.
  1938.  
  1939.  - Grammar: delim ;
  1940.           set foo bar;
  1941.      delimits the extent of the restfix operator `set'.
  1942.  
  1943.   ---------- Footnotes ----------
  1944.  
  1945.   (1) How do I know this?  I parsed 250kbyte of random input (an e-mail
  1946. file) with a non-trivial grammar utilizing all constructs.
  1947.  
  1948. 
  1949. File: slib.info,  Node: Ruleset Definition and Use,  Next: Token definition,  Prev: Precedence Parsing Overview,  Up: Precedence Parsing
  1950.  
  1951. Ruleset Definition and Use
  1952. --------------------------
  1953.  
  1954.  - Variable: *syn-defs*
  1955.      A grammar is built by one or more calls to `prec:define-grammar'.
  1956.      The rules are appended to *SYN-DEFS*.  The value of *SYN-DEFS* is
  1957.      the grammar suitable for passing as an argument to `prec:parse'.
  1958.  
  1959.  - Constant: *syn-ignore-whitespace*
  1960.      Is a nearly empty grammar with whitespace characters set to group
  1961.      0, which means they will not be made into tokens.  Most rulesets
  1962.      will want to start with `*syn-ignore-whitespace*'
  1963.  
  1964. In order to start defining a grammar, either
  1965.  
  1966.      (set! *syn-defs* '())
  1967.  
  1968. or
  1969.  
  1970.      (set! *syn-defs* *syn-ignore-whitespace*)
  1971.  
  1972.  - Function: prec:define-grammar RULE1 ...
  1973.      Appends RULE1 ... to *SYN-DEFS*.  `prec:define-grammar' is used to
  1974.      define both the character classes and rules for tokens.
  1975.  
  1976. Once your grammar is defined, save the value of `*syn-defs*' in a
  1977. variable (for use when calling `prec:parse').
  1978.  
  1979.      (define my-ruleset *syn-defs*)
  1980.  
  1981.  - Function: prec:parse RULESET DELIM
  1982.  - Function: prec:parse RULESET DELIM PORT
  1983.      The RULESET argument must be a list of rules as constructed by
  1984.      `prec:define-grammar' and extracted from *SYN-DEFS*.
  1985.  
  1986.      The token DELIM may be a character, symbol, or string.  A
  1987.      character DELIM argument will match only a character token; i.e. a
  1988.      character for which no token-group is assigned.  A symbols or
  1989.      string will match only a token string; i.e. a token resulting from
  1990.      a token group.
  1991.  
  1992.      `prec:parse' reads a RULESET grammar expression delimited by DELIM
  1993.      from the given input PORT.  `prec:parse' returns the next object
  1994.      parsable from the given input PORT, updating PORT to point to the
  1995.      first character past the end of the external representation of the
  1996.      object.
  1997.  
  1998.      If an end of file is encountered in the input before any
  1999.      characters are found that can begin an object, then an end of file
  2000.      object is returned.  If a delimiter (such as DELIM) is found
  2001.      before any characters are found that can begin an object, then
  2002.      `#f' is returned.
  2003.  
  2004.      The PORT argument may be omitted, in which case it defaults to the
  2005.      value returned by `current-input-port'.  It is an error to parse
  2006.      from a closed port.
  2007.  
  2008. 
  2009. File: slib.info,  Node: Token definition,  Next: Nud and Led Definition,  Prev: Ruleset Definition and Use,  Up: Precedence Parsing
  2010.  
  2011. Token definition
  2012. ----------------
  2013.  
  2014.  - Function: tok:char-group GROUP CHARS CHARS-PROC
  2015.      The argument CHARS may be a single character, a list of
  2016.      characters, or a string.  Each character in CHARS is treated as
  2017.      though `tok:char-group' was called with that character alone.
  2018.  
  2019.      The argument CHARS-PROC must be a procedure of one argument, a
  2020.      list of characters.  After `tokenize' has finished accumulating
  2021.      the characters for a token, it calls CHARS-PROC with the list of
  2022.      characters.  The value returned is the token which `tokenize'
  2023.      returns.
  2024.  
  2025.      The argument GROUP may be an exact integer or a procedure of one
  2026.      character argument.  The following discussion concerns the
  2027.      treatment which the tokenizing routine, `tokenize', will accord to
  2028.      characters on the basis of their groups.
  2029.  
  2030.      When GROUP is a non-zero integer, characters whose group number is
  2031.      equal to or exactly one less than GROUP will continue to
  2032.      accumulate.  Any other character causes the accumulation to stop
  2033.      (until a new token is to be read).
  2034.  
  2035.      The GROUP of zero is special.  These characters are ignored when
  2036.      parsed pending a token, and stop the accumulation of token
  2037.      characters when the accumulation has already begun.  Whitespace
  2038.      characters are usually put in group 0.
  2039.  
  2040.      If GROUP is a procedure, then, when triggerd by the occurence of
  2041.      an initial (no accumulation) CHARS character, this procedure will
  2042.      be repeatedly called with each successive character from the input
  2043.      stream until the GROUP procedure returns a non-false value.
  2044.  
  2045. The following convenient constants are provided for use with
  2046. `tok:char-group'.
  2047.  
  2048.  - Constant: tok:decimal-digits
  2049.      Is the string `"0123456789"'.
  2050.  
  2051.  - Constant: tok:upper-case
  2052.      Is the string consisting of all upper-case letters
  2053.      ("ABCDEFGHIJKLMNOPQRSTUVWXYZ").
  2054.  
  2055.  - Constant: tok:lower-case
  2056.      Is the string consisting of all lower-case letters
  2057.      ("abcdefghijklmnopqrstuvwxyz").
  2058.  
  2059.  - Constant: tok:whitespaces
  2060.      Is the string consisting of all characters between 0 and 255 for
  2061.      which `char-whitespace?' returns true.
  2062.  
  2063. 
  2064. File: slib.info,  Node: Nud and Led Definition,  Next: Grammar Rule Definition,  Prev: Token definition,  Up: Precedence Parsing
  2065.  
  2066. Nud and Led Definition
  2067. ----------------------
  2068.  
  2069.   This section describes advanced features.  You can skip this section
  2070. on first reading.
  2071.  
  2072. The "Null Denotation" (or "nud") of a token is the procedure and
  2073. arguments applying for that token when "Left", an unclaimed parsed
  2074. expression is not extant.
  2075.  
  2076. The "Left Denotation" (or "led") of a token is the procedure,
  2077. arguments, and lbp applying for that token when there is a "Left", an
  2078. unclaimed parsed expression.
  2079.  
  2080. In his paper,
  2081.  
  2082.      Pratt, V. R.  Top Down Operator Precendence.  `SIGACT/SIGPLAN
  2083.      Symposium on Principles of Programming Languages', Boston, 1973,
  2084.      pages 41-51
  2085.  
  2086.   the "left binding power" (or "lbp") was an independent property of
  2087. tokens.  I think this was done in order to allow tokens with NUDs but
  2088. not LEDs to also be used as delimiters, which was a problem for
  2089. statically defined syntaxes.  It turns out that *dynamically binding*
  2090. NUDs and LEDs allows them independence.
  2091.  
  2092. For the rule-defining procedures that follow, the variable TK may be a
  2093. character, string, or symbol, or a list composed of characters,
  2094. strings, and symbols.  Each element of TK is treated as though the
  2095. procedure were called for each element.
  2096.  
  2097. Character TK arguments will match only character tokens; i.e.
  2098. characters for which no token-group is assigned.  Symbols and strings
  2099. will both match token strings; i.e. tokens resulting from token groups.
  2100.  
  2101.  - Function: prec:make-nud TK SOP ARG1 ...
  2102.      Returns a rule specifying that SOP be called when TK is parsed.
  2103.      If SOP is a procedure, it is called with TK and ARG1 ... as its
  2104.      arguments; the resulting value is incorporated into the expression
  2105.      being built.  Otherwise, `(list SOP ARG1 ...)' is incorporated.
  2106.  
  2107. If no NUD has been defined for a token; then if that token is a string,
  2108. it is converted to a symbol and returned; if not a string, the token is
  2109. returned.
  2110.  
  2111.  - Function: prec:make-led TK SOP ARG1 ...
  2112.      Returns a rule specifying that SOP be called when TK is parsed and
  2113.      LEFT has an unclaimed parsed expression.  If SOP is a procedure,
  2114.      it is called with LEFT, TK, and ARG1 ... as its arguments; the
  2115.      resulting value is incorporated into the expression being built.
  2116.      Otherwise, LEFT is incorporated.
  2117.  
  2118. If no LED has been defined for a token, and LEFT is set, the parser
  2119. issues a warning.
  2120.  
  2121. 
  2122. File: slib.info,  Node: Grammar Rule Definition,  Prev: Nud and Led Definition,  Up: Precedence Parsing
  2123.  
  2124. Grammar Rule Definition
  2125. -----------------------
  2126.  
  2127. Here are procedures for defining rules for the syntax types introduced
  2128. in *Note Precedence Parsing Overview::.
  2129.  
  2130. For the rule-defining procedures that follow, the variable TK may be a
  2131. character, string, or symbol, or a list composed of characters,
  2132. strings, and symbols.  Each element of TK is treated as though the
  2133. procedure were called for each element.
  2134.  
  2135. For procedures prec:delim, ..., prec:prestfix, if the SOP argument is
  2136. `#f', then the token which triggered this rule is converted to a symbol
  2137. and returned.  A false SOP argument to the procedures prec:commentfix,
  2138. prec:matchfix, or prec:inmatchfix has a different meaning.
  2139.  
  2140. Character TK arguments will match only character tokens; i.e.
  2141. characters for which no token-group is assigned.  Symbols and strings
  2142. will both match token strings; i.e. tokens resulting from token groups.
  2143.  
  2144.  - Function: prec:delim TK
  2145.      Returns a rule specifying that TK should not be returned from
  2146.      parsing; i.e. TK's function is purely syntactic.  The end-of-file
  2147.      is always treated as a delimiter.
  2148.  
  2149.  - Function: prec:nofix TK SOP
  2150.      Returns a rule specifying the following actions take place when TK
  2151.      is parsed:
  2152.         * If SOP is a procedure, it is called with no arguments; the
  2153.           resulting value is incorporated into the expression being
  2154.           built.  Otherwise, the list of SOP is incorporated.
  2155.  
  2156.  - Function: prec:prefix TK SOP BP RULE1 ...
  2157.      Returns a rule specifying the following actions take place when TK
  2158.      is parsed:
  2159.         * The rules RULE1 ... augment and, in case of conflict, override
  2160.           rules currently in effect.
  2161.  
  2162.         * `prec:parse1' is called with binding-power BP.
  2163.  
  2164.         * If SOP is a procedure, it is called with the expression
  2165.           returned from `prec:parse1'; the resulting value is
  2166.           incorporated into the expression being built.  Otherwise, the
  2167.           list of SOP and the expression returned from `prec:parse1' is
  2168.           incorporated.
  2169.  
  2170.         * The ruleset in effect before TK was parsed is restored; RULE1
  2171.           ... are forgotten.
  2172.  
  2173.  - Function: prec:infix TK SOP LBP BP RULE1 ...
  2174.      Returns a rule declaring the left-binding-precedence of the token
  2175.      TK is LBP and specifying the following actions take place when TK
  2176.      is parsed:
  2177.         * The rules RULE1 ... augment and, in case of conflict, override
  2178.           rules currently in effect.
  2179.  
  2180.         * One expression is parsed with binding-power LBP.  If instead a
  2181.           delimiter is encountered, a warning is issued.
  2182.  
  2183.         * If SOP is a procedure, it is applied to the list of LEFT and
  2184.           the parsed expression; the resulting value is incorporated
  2185.           into the expression being built.  Otherwise, the list of SOP,
  2186.           the LEFT expression, and the parsed expression is
  2187.           incorporated.
  2188.  
  2189.         * The ruleset in effect before TK was parsed is restored; RULE1
  2190.           ... are forgotten.
  2191.  
  2192.  - Function: prec:nary TK SOP BP
  2193.      Returns a rule declaring the left-binding-precedence of the token
  2194.      TK is BP and specifying the following actions take place when TK
  2195.      is parsed:
  2196.         * Expressions are parsed with binding-power BP as far as they
  2197.           are interleaved with the token TK.
  2198.  
  2199.         * If SOP is a procedure, it is applied to the list of LEFT and
  2200.           the parsed expressions; the resulting value is incorporated
  2201.           into the expression being built.  Otherwise, the list of SOP,
  2202.           the LEFT expression, and the parsed expressions is
  2203.           incorporated.
  2204.  
  2205.  - Function: prec:postfix TK SOP LBP
  2206.      Returns a rule declaring the left-binding-precedence of the token
  2207.      TK is LBP and specifying the following actions take place when TK
  2208.      is parsed:
  2209.         * If SOP is a procedure, it is called with the LEFT expression;
  2210.           the resulting value is incorporated into the expression being
  2211.           built.  Otherwise, the list of SOP and the LEFT expression is
  2212.           incorporated.
  2213.  
  2214.  - Function: prec:prestfix TK SOP BP RULE1 ...
  2215.      Returns a rule specifying the following actions take place when TK
  2216.      is parsed:
  2217.         * The rules RULE1 ... augment and, in case of conflict, override
  2218.           rules currently in effect.
  2219.  
  2220.         * Expressions are parsed with binding-power BP until a
  2221.           delimiter is reached.
  2222.  
  2223.         * If SOP is a procedure, it is applied to the list of parsed
  2224.           expressions; the resulting value is incorporated into the
  2225.           expression being built.  Otherwise, the list of SOP and the
  2226.           parsed expressions is incorporated.
  2227.  
  2228.         * The ruleset in effect before TK was parsed is restored; RULE1
  2229.           ... are forgotten.
  2230.  
  2231.  - Function: prec:commentfix TK STP MATCH RULE1 ...
  2232.      Returns rules specifying the following actions take place when TK
  2233.      is parsed:
  2234.         * The rules RULE1 ... augment and, in case of conflict, override
  2235.           rules currently in effect.
  2236.  
  2237.         * Characters are read until and end-of-file or a sequence of
  2238.           characters is read which matches the *string* MATCH.
  2239.  
  2240.         * If STP is a procedure, it is called with the string of all
  2241.           that was read between the TK and MATCH (exclusive).
  2242.  
  2243.         * The ruleset in effect before TK was parsed is restored; RULE1
  2244.           ... are forgotten.
  2245.  
  2246.      Parsing of commentfix syntax differs from the others in several
  2247.      ways.  It reads directly from input without tokenizing; It calls
  2248.      STP but does not return its value; nay any value.  I added the STP
  2249.      argument so that comment text could be echoed.
  2250.  
  2251.  - Function: prec:matchfix TK SOP SEP MATCH RULE1 ...
  2252.      Returns a rule specifying the following actions take place when TK
  2253.      is parsed:
  2254.         * The rules RULE1 ... augment and, in case of conflict, override
  2255.           rules currently in effect.
  2256.  
  2257.         * A rule declaring the token MATCH a delimiter takes effect.
  2258.  
  2259.         * Expressions are parsed with binding-power `0' until the token
  2260.           MATCH is reached.  If the token SEP does not appear between
  2261.           each pair of expressions parsed, a warning is issued.
  2262.  
  2263.         * If SOP is a procedure, it is applied to the list of parsed
  2264.           expressions; the resulting value is incorporated into the
  2265.           expression being built.  Otherwise, the list of SOP and the
  2266.           parsed expressions is incorporated.
  2267.  
  2268.         * The ruleset in effect before TK was parsed is restored; RULE1
  2269.           ... are forgotten.
  2270.  
  2271.  - Function: prec:inmatchfix TK SOP SEP MATCH LBP RULE1 ...
  2272.      Returns a rule declaring the left-binding-precedence of the token
  2273.      TK is LBP and specifying the following actions take place when TK
  2274.      is parsed:
  2275.         * The rules RULE1 ... augment and, in case of conflict, override
  2276.           rules currently in effect.
  2277.  
  2278.         * A rule declaring the token MATCH a delimiter takes effect.
  2279.  
  2280.         * Expressions are parsed with binding-power `0' until the token
  2281.           MATCH is reached.  If the token SEP does not appear between
  2282.           each pair of expressions parsed, a warning is issued.
  2283.  
  2284.         * If SOP is a procedure, it is applied to the list of LEFT and
  2285.           the parsed expressions; the resulting value is incorporated
  2286.           into the expression being built.  Otherwise, the list of SOP,
  2287.           the LEFT expression, and the parsed expressions is
  2288.           incorporated.
  2289.  
  2290.         * The ruleset in effect before TK was parsed is restored; RULE1
  2291.           ... are forgotten.
  2292.  
  2293. 
  2294. File: slib.info,  Node: Format,  Next: Standard Formatted I/O,  Prev: Precedence Parsing,  Up: Textual Conversion Packages
  2295.  
  2296. Format (version 3.0)
  2297. ====================
  2298.  
  2299.   `(require 'format)'
  2300.  
  2301. * Menu:
  2302.  
  2303. * Format Interface::
  2304. * Format Specification::
  2305.  
  2306. 
  2307. File: slib.info,  Node: Format Interface,  Next: Format Specification,  Prev: Format,  Up: Format
  2308.  
  2309. Format Interface
  2310. ----------------
  2311.  
  2312.  - Function: format DESTINATION FORMAT-STRING . ARGUMENTS
  2313.      An almost complete implementation of Common LISP format description
  2314.      according to the CL reference book `Common LISP' from Guy L.
  2315.      Steele, Digital Press.  Backward compatible to most of the
  2316.      available Scheme format implementations.
  2317.  
  2318.      Returns `#t', `#f' or a string; has side effect of printing
  2319.      according to FORMAT-STRING.  If DESTINATION is `#t', the output is
  2320.      to the current output port and `#t' is returned.  If DESTINATION
  2321.      is `#f', a formatted string is returned as the result of the call.
  2322.      NEW: If DESTINATION is a string, DESTINATION is regarded as the
  2323.      format string; FORMAT-STRING is then the first argument and the
  2324.      output is returned as a string. If DESTINATION is a number, the
  2325.      output is to the current error port if available by the
  2326.      implementation. Otherwise DESTINATION must be an output port and
  2327.      `#t' is returned.
  2328.  
  2329.      FORMAT-STRING must be a string.  In case of a formatting error
  2330.      format returns `#f' and prints a message on the current output or
  2331.      error port.  Characters are output as if the string were output by
  2332.      the `display' function with the exception of those prefixed by a
  2333.      tilde (~).  For a detailed description of the FORMAT-STRING syntax
  2334.      please consult a Common LISP format reference manual.  For a test
  2335.      suite to verify this format implementation load `formatst.scm'.
  2336.      Please send bug reports to `lutzeb@cs.tu-berlin.de'.
  2337.  
  2338.      Note: `format' is not reentrant, i.e. only one `format'-call may
  2339.      be executed at a time.
  2340.  
  2341.  
  2342. 
  2343. File: slib.info,  Node: Format Specification,  Prev: Format Interface,  Up: Format
  2344.  
  2345. Format Specification (Format version 3.0)
  2346. -----------------------------------------
  2347.  
  2348.   Please consult a Common LISP format reference manual for a detailed
  2349. description of the format string syntax.  For a demonstration of the
  2350. implemented directives see `formatst.scm'.
  2351.  
  2352.   This implementation supports directive parameters and modifiers (`:'
  2353. and `@' characters). Multiple parameters must be separated by a comma
  2354. (`,').  Parameters can be numerical parameters (positive or negative),
  2355. character parameters (prefixed by a quote character (`''), variable
  2356. parameters (`v'), number of rest arguments parameter (`#'), empty and
  2357. default parameters.  Directive characters are case independent. The
  2358. general form of a directive is:
  2359.  
  2360. DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER
  2361.  
  2362. DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ]
  2363.  
  2364. Implemented CL Format Control Directives
  2365. ........................................
  2366.  
  2367.   Documentation syntax: Uppercase characters represent the corresponding
  2368. control directive characters. Lowercase characters represent control
  2369. directive parameter descriptions.
  2370.  
  2371. `~A'
  2372.      Any (print as `display' does).
  2373.     `~@A'
  2374.           left pad.
  2375.  
  2376.     `~MINCOL,COLINC,MINPAD,PADCHARA'
  2377.           full padding.
  2378.  
  2379. `~S'
  2380.      S-expression (print as `write' does).
  2381.     `~@S'
  2382.           left pad.
  2383.  
  2384.     `~MINCOL,COLINC,MINPAD,PADCHARS'
  2385.           full padding.
  2386.  
  2387. `~D'
  2388.      Decimal.
  2389.     `~@D'
  2390.           print number sign always.
  2391.  
  2392.     `~:D'
  2393.           print comma separated.
  2394.  
  2395.     `~MINCOL,PADCHAR,COMMACHARD'
  2396.           padding.
  2397.  
  2398. `~X'
  2399.      Hexadecimal.
  2400.     `~@X'
  2401.           print number sign always.
  2402.  
  2403.     `~:X'
  2404.           print comma separated.
  2405.  
  2406.     `~MINCOL,PADCHAR,COMMACHARX'
  2407.           padding.
  2408.  
  2409. `~O'
  2410.      Octal.
  2411.     `~@O'
  2412.           print number sign always.
  2413.  
  2414.     `~:O'
  2415.           print comma separated.
  2416.  
  2417.     `~MINCOL,PADCHAR,COMMACHARO'
  2418.           padding.
  2419.  
  2420. `~B'
  2421.      Binary.
  2422.     `~@B'
  2423.           print number sign always.
  2424.  
  2425.     `~:B'
  2426.           print comma separated.
  2427.  
  2428.     `~MINCOL,PADCHAR,COMMACHARB'
  2429.           padding.
  2430.  
  2431. `~NR'
  2432.      Radix N.
  2433.     `~N,MINCOL,PADCHAR,COMMACHARR'
  2434.           padding.
  2435.  
  2436. `~@R'
  2437.      print a number as a Roman numeral.
  2438.  
  2439. `~:@R'
  2440.      print a number as an "old fashioned" Roman numeral.
  2441.  
  2442. `~:R'
  2443.      print a number as an ordinal English number.
  2444.  
  2445. `~:@R'
  2446.      print a number as a cardinal English number.
  2447.  
  2448. `~P'
  2449.      Plural.
  2450.     `~@P'
  2451.           prints `y' and `ies'.
  2452.  
  2453.     `~:P'
  2454.           as `~P but jumps 1 argument backward.'
  2455.  
  2456.     `~:@P'
  2457.           as `~@P but jumps 1 argument backward.'
  2458.  
  2459. `~C'
  2460.      Character.
  2461.     `~@C'
  2462.           prints a character as the reader can understand it (i.e. `#\'
  2463.           prefixing).
  2464.  
  2465.     `~:C'
  2466.           prints a character as emacs does (eg. `^C' for ASCII 03).
  2467.  
  2468. `~F'
  2469.      Fixed-format floating-point (prints a flonum like MMM.NNN).
  2470.     `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF'
  2471.  
  2472.     `~@F'
  2473.           If the number is positive a plus sign is printed.
  2474.  
  2475. `~E'
  2476.      Exponential floating-point (prints a flonum like MMM.NNN`E'EE).
  2477.     `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE'
  2478.  
  2479.     `~@E'
  2480.           If the number is positive a plus sign is printed.
  2481.  
  2482. `~G'
  2483.      General floating-point (prints a flonum either fixed or
  2484.      exponential).
  2485.     `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG'
  2486.  
  2487.     `~@G'
  2488.           If the number is positive a plus sign is printed.
  2489.  
  2490. `~$'
  2491.      Dollars floating-point (prints a flonum in fixed with signs
  2492.      separated).
  2493.     `~DIGITS,SCALE,WIDTH,PADCHAR$'
  2494.  
  2495.     `~@$'
  2496.           If the number is positive a plus sign is printed.
  2497.  
  2498.     `~:@$'
  2499.           A sign is always printed and appears before the padding.
  2500.  
  2501.     `~:$'
  2502.           The sign appears before the padding.
  2503.  
  2504. `~%'
  2505.      Newline.
  2506.     `~N%'
  2507.           print N newlines.
  2508.  
  2509. `~&'
  2510.      print newline if not at the beginning of the output line.
  2511.     `~N&'
  2512.           prints `~&' and then N-1 newlines.
  2513.  
  2514. `~|'
  2515.      Page Separator.
  2516.     `~N|'
  2517.           print N page separators.
  2518.  
  2519. `~~'
  2520.      Tilde.
  2521.     `~N~'
  2522.           print N tildes.
  2523.  
  2524. `~'<newline>
  2525.      Continuation Line.
  2526.     `~:'<newline>
  2527.           newline is ignored, white space left.
  2528.  
  2529.     `~@'<newline>
  2530.           newline is left, white space ignored.
  2531.  
  2532. `~T'
  2533.      Tabulation.
  2534.     `~@T'
  2535.           relative tabulation.
  2536.  
  2537.     `~COLNUM,COLINCT'
  2538.           full tabulation.
  2539.  
  2540. `~?'
  2541.      Indirection (expects indirect arguments as a list).
  2542.     `~@?'
  2543.           extracts indirect arguments from format arguments.
  2544.  
  2545. `~(STR~)'
  2546.      Case conversion (converts by `string-downcase').
  2547.     `~:(STR~)'
  2548.           converts by `string-capitalize'.
  2549.  
  2550.     `~@(STR~)'
  2551.           converts by `string-capitalize-first'.
  2552.  
  2553.     `~:@(STR~)'
  2554.           converts by `string-upcase'.
  2555.  
  2556. `~*'
  2557.      Argument Jumping (jumps 1 argument forward).
  2558.     `~N*'
  2559.           jumps N arguments forward.
  2560.  
  2561.     `~:*'
  2562.           jumps 1 argument backward.
  2563.  
  2564.     `~N:*'
  2565.           jumps N arguments backward.
  2566.  
  2567.     `~@*'
  2568.           jumps to the 0th argument.
  2569.  
  2570.     `~N@*'
  2571.           jumps to the Nth argument (beginning from 0)
  2572.  
  2573. `~[STR0~;STR1~;...~;STRN~]'
  2574.      Conditional Expression (numerical clause conditional).
  2575.     `~N['
  2576.           take argument from N.
  2577.  
  2578.     `~@['
  2579.           true test conditional.
  2580.  
  2581.     `~:['
  2582.           if-else-then conditional.
  2583.  
  2584.     `~;'
  2585.           clause separator.
  2586.  
  2587.     `~:;'
  2588.           default clause follows.
  2589.  
  2590. `~{STR~}'
  2591.      Iteration (args come from the next argument (a list)).
  2592.     `~N{'
  2593.           at most N iterations.
  2594.  
  2595.     `~:{'
  2596.           args from next arg (a list of lists).
  2597.  
  2598.     `~@{'
  2599.           args from the rest of arguments.
  2600.  
  2601.     `~:@{'
  2602.           args from the rest args (lists).
  2603.  
  2604. `~^'
  2605.      Up and out.
  2606.     `~N^'
  2607.           aborts if N = 0
  2608.  
  2609.     `~N,M^'
  2610.           aborts if N = M
  2611.  
  2612.     `~N,M,K^'
  2613.           aborts if N <= M <= K
  2614.  
  2615. Not Implemented CL Format Control Directives
  2616. ............................................
  2617.  
  2618. `~:A'
  2619.      print `#f' as an empty list (see below).
  2620.  
  2621. `~:S'
  2622.      print `#f' as an empty list (see below).
  2623.  
  2624. `~<~>'
  2625.      Justification.
  2626.  
  2627. `~:^'
  2628.      (sorry I don't understand its semantics completely)
  2629.  
  2630. Extended, Replaced and Additional Control Directives
  2631. ....................................................
  2632.  
  2633. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD'
  2634.  
  2635. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX'
  2636.  
  2637. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO'
  2638.  
  2639. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB'
  2640.  
  2641. `~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR'
  2642.      COMMAWIDTH is the number of characters between two comma
  2643.      characters.
  2644.  
  2645. `~I'
  2646.      print a R4RS complex number as `~F~@Fi' with passed parameters for
  2647.      `~F'.
  2648.  
  2649. `~Y'
  2650.      Pretty print formatting of an argument for scheme code lists.
  2651.  
  2652. `~K'
  2653.      Same as `~?.'
  2654.  
  2655. `~!'
  2656.      Flushes the output if format DESTINATION is a port.
  2657.  
  2658. `~_'
  2659.      Print a `#\space' character
  2660.     `~N_'
  2661.           print N `#\space' characters.
  2662.  
  2663. `~/'
  2664.      Print a `#\tab' character
  2665.     `~N/'
  2666.           print N `#\tab' characters.
  2667.  
  2668. `~NC'
  2669.      Takes N as an integer representation for a character. No arguments
  2670.      are consumed. N is converted to a character by `integer->char'.  N
  2671.      must be a positive decimal number.
  2672.  
  2673. `~:S'
  2674.      Print out readproof.  Prints out internal objects represented as
  2675.      `#<...>' as strings `"#<...>"' so that the format output can always
  2676.      be processed by `read'.
  2677.  
  2678. `~:A'
  2679.      Print out readproof.  Prints out internal objects represented as
  2680.      `#<...>' as strings `"#<...>"' so that the format output can always
  2681.      be processed by `read'.
  2682.  
  2683. `~Q'
  2684.      Prints information and a copyright notice on the format
  2685.      implementation.
  2686.     `~:Q'
  2687.           prints format version.
  2688.  
  2689. `~F, ~E, ~G, ~$'
  2690.      may also print number strings, i.e. passing a number as a string
  2691.      and format it accordingly.
  2692.  
  2693. Configuration Variables
  2694. .......................
  2695.  
  2696.   Format has some configuration variables at the beginning of
  2697. `format.scm' to suit the systems and users needs. There should be no
  2698. modification necessary for the configuration that comes with SLIB.  If
  2699. modification is desired the variable should be set after the format
  2700. code is loaded. Format detects automatically if the running scheme
  2701. system implements floating point numbers and complex numbers.
  2702.  
  2703. FORMAT:SYMBOL-CASE-CONV
  2704.      Symbols are converted by `symbol->string' so the case type of the
  2705.      printed symbols is implementation dependent.
  2706.      `format:symbol-case-conv' is a one arg closure which is either
  2707.      `#f' (no conversion), `string-upcase', `string-downcase' or
  2708.      `string-capitalize'. (default `#f')
  2709.  
  2710. FORMAT:IOBJ-CASE-CONV
  2711.      As FORMAT:SYMBOL-CASE-CONV but applies for the representation of
  2712.      implementation internal objects. (default `#f')
  2713.  
  2714. FORMAT:EXPCH
  2715.      The character prefixing the exponent value in `~E' printing.
  2716.      (default `#\E')
  2717.  
  2718. Compatibility With Other Format Implementations
  2719. ...............................................
  2720.  
  2721. SLIB format 2.x:
  2722.      See `format.doc'.
  2723.  
  2724. SLIB format 1.4:
  2725.      Downward compatible except for padding support and `~A', `~S',
  2726.      `~P', `~X' uppercase printing.  SLIB format 1.4 uses C-style
  2727.      `printf' padding support which is completely replaced by the CL
  2728.      `format' padding style.
  2729.  
  2730. MIT C-Scheme 7.1:
  2731.      Downward compatible except for `~', which is not documented
  2732.      (ignores all characters inside the format string up to a newline
  2733.      character).  (7.1 implements `~a', `~s', ~NEWLINE, `~~', `~%',
  2734.      numerical and variable parameters and `:/@' modifiers in the CL
  2735.      sense).
  2736.  
  2737. Elk 1.5/2.0:
  2738.      Downward compatible except for `~A' and `~S' which print in
  2739.      uppercase.  (Elk implements `~a', `~s', `~~', and `~%' (no
  2740.      directive parameters or modifiers)).
  2741.  
  2742. Scheme->C 01nov91:
  2743.      Downward compatible except for an optional destination parameter:
  2744.      S2C accepts a format call without a destination which returns a
  2745.      formatted string. This is equivalent to a #f destination in S2C.
  2746.      (S2C implements `~a', `~s', `~c', `~%', and `~~' (no directive
  2747.      parameters or modifiers)).
  2748.  
  2749.   This implementation of format is solely useful in the SLIB context
  2750. because it requires other components provided by SLIB.
  2751.  
  2752. 
  2753. File: slib.info,  Node: Standard Formatted I/O,  Next: Programs and Arguments,  Prev: Format,  Up: Textual Conversion Packages
  2754.  
  2755. Standard Formatted I/O
  2756. ======================
  2757.  
  2758. * Menu:
  2759.  
  2760. * Standard Formatted Output::   'printf
  2761. * Standard Formatted Input::    'scanf
  2762.  
  2763. stdio
  2764. -----
  2765.  
  2766.   `(require 'stdio)'
  2767.  
  2768.   `require's `printf' and `scanf' and additionally defines the symbols:
  2769.  
  2770.  - Variable: stdin
  2771.      Defined to be `(current-input-port)'.
  2772.  
  2773.  - Variable: stdout
  2774.      Defined to be `(current-output-port)'.
  2775.  
  2776.  - Variable: stderr
  2777.      Defined to be `(current-error-port)'.
  2778.  
  2779. 
  2780. File: slib.info,  Node: Standard Formatted Output,  Next: Standard Formatted Input,  Prev: Standard Formatted I/O,  Up: Standard Formatted I/O
  2781.  
  2782. Standard Formatted Output
  2783. -------------------------
  2784.  
  2785.   `(require 'printf)'
  2786.  
  2787.  - Procedure: printf FORMAT ARG1 ...
  2788.  - Procedure: fprintf PORT FORMAT ARG1 ...
  2789.  - Procedure: sprintf STR FORMAT ARG1 ...
  2790.  - Procedure: sprintf #F FORMAT ARG1 ...
  2791.  - Procedure: sprintf K FORMAT ARG1 ...
  2792.      Each function converts, formats, and outputs its ARG1 ...
  2793.      arguments according to the control string FORMAT argument and
  2794.      returns the number of characters output.
  2795.  
  2796.      `printf' sends its output to the port `(current-output-port)'.
  2797.      `fprintf' sends its output to the port PORT.  `sprintf'
  2798.      `string-set!'s locations of the non-constant string argument STR
  2799.      to the output characters.
  2800.  
  2801.      Two extensions of `sprintf' return new strings.  If the first
  2802.      argument is `#f', then the returned string's length is as many
  2803.      characters as specified by the FORMAT and data; if the first
  2804.      argument is a non-negative integer K, then the length of the
  2805.      returned string is also bounded by K.
  2806.  
  2807.      The string FORMAT contains plain characters which are copied to
  2808.      the output stream, and conversion specifications, each of which
  2809.      results in fetching zero or more of the arguments ARG1 ....  The
  2810.      results are undefined if there are an insufficient number of
  2811.      arguments for the format.  If FORMAT is exhausted while some of the
  2812.      ARG1 ... arguments remain unused, the excess ARG1 ... arguments
  2813.      are ignored.
  2814.  
  2815.      The conversion specifications in a format string have the form:
  2816.  
  2817.           % [ FLAGS ] [ WIDTH ] [ . PRECISION ] [ TYPE ] CONVERSION
  2818.  
  2819.      An output conversion specifications consist of an initial `%'
  2820.      character followed in sequence by:
  2821.  
  2822.         * Zero or more "flag characters" that modify the normal
  2823.           behavior of the conversion specification.
  2824.  
  2825.          `-'
  2826.                Left-justify the result in the field.  Normally the
  2827.                result is right-justified.
  2828.  
  2829.          `+'
  2830.                For the signed `%d' and `%i' conversions and all inexact
  2831.                conversions, prefix a plus sign if the value is positive.
  2832.  
  2833.          ` '
  2834.                For the signed `%d' and `%i' conversions, if the result
  2835.                doesn't start with a plus or minus sign, prefix it with
  2836.                a space character instead.  Since the `+' flag ensures
  2837.                that the result includes a sign, this flag is ignored if
  2838.                both are specified.
  2839.  
  2840.          `#'
  2841.                For inexact conversions, `#' specifies that the result
  2842.                should always include a decimal point, even if no digits
  2843.                follow it.  For the `%g' and `%G' conversions, this also
  2844.                forces trailing zeros after the decimal point to be
  2845.                printed where they would otherwise be elided.
  2846.  
  2847.                For the `%o' conversion, force the leading digit to be
  2848.                `0', as if by increasing the precision.  For `%x' or
  2849.                `%X', prefix a leading `0x' or `0X' (respectively) to
  2850.                the result.  This doesn't do anything useful for the
  2851.                `%d', `%i', or `%u' conversions.  Using this flag
  2852.                produces output which can be parsed by the `scanf'
  2853.                functions with the `%i' conversion (*note Standard
  2854.                Formatted Input::.).
  2855.  
  2856.          `0'
  2857.                Pad the field with zeros instead of spaces.  The zeros
  2858.                are placed after any indication of sign or base.  This
  2859.                flag is ignored if the `-' flag is also specified, or if
  2860.                a precision is specified for an exact converson.
  2861.  
  2862.         * An optional decimal integer specifying the "minimum field
  2863.           width".  If the normal conversion produces fewer characters
  2864.           than this, the field is padded (with spaces or zeros per the
  2865.           `0' flag) to the specified width.  This is a *minimum* width;
  2866.           if the normal conversion produces more characters than this,
  2867.           the field is *not* truncated.
  2868.  
  2869.           Alternatively, if the field width is `*', the next argument
  2870.           in the argument list (before the actual value to be printed)
  2871.           is used as the field width.  The width value must be an
  2872.           integer.  If the value is negative it is as though the `-'
  2873.           flag is set (see above) and the absolute value is used as the
  2874.           field width.
  2875.  
  2876.         * An optional "precision" to specify the number of digits to be
  2877.           written for numeric conversions and the maximum field width
  2878.           for string conversions.  The precision is specified by a
  2879.           period (`.') followed optionally by a decimal integer (which
  2880.           defaults to zero if omitted).
  2881.  
  2882.           Alternatively, if the precision is `.*', the next argument in
  2883.           the argument list (before the actual value to be printed) is
  2884.           used as the precision.  The value must be an integer, and is
  2885.           ignored if negative.  If you specify `*' for both the field
  2886.           width and precision, the field width argument precedes the
  2887.           precision argument.  The `.*' precision is an enhancement.  C
  2888.           library versions may not accept this syntax.
  2889.  
  2890.           For the `%f', `%e', and `%E' conversions, the precision
  2891.           specifies how many digits follow the decimal-point character.
  2892.           The default precision is `6'.  If the precision is
  2893.           explicitly `0', the decimal point character is suppressed.
  2894.  
  2895.           For the `%g' and `%G' conversions, the precision specifies how
  2896.           many significant digits to print.  Significant digits are the
  2897.           first digit before the decimal point, and all the digits
  2898.           after it.  If the precision is `0' or not specified for `%g'
  2899.           or `%G', it is treated like a value of `1'.  If the value
  2900.           being printed cannot be expressed accurately in the specified
  2901.           number of digits, the value is rounded to the nearest number
  2902.           that fits.
  2903.  
  2904.           For exact conversions, if a precision is supplied it
  2905.           specifies the minimum number of digits to appear; leading
  2906.           zeros are produced if necessary.  If a precision is not
  2907.           supplied, the number is printed with as many digits as
  2908.           necessary.  Converting an exact `0' with an explicit
  2909.           precision of zero produces no characters.
  2910.  
  2911.         * An optional one of `l', `h' or `L', which is ignored for
  2912.           numeric conversions.  It is an error to specify these
  2913.           modifiers for non-numeric conversions.
  2914.  
  2915.         * A character that specifies the conversion to be applied.
  2916.  
  2917. Exact Conversions
  2918. .................
  2919.  
  2920.     `d', `i'
  2921.           Print an integer as a signed decimal number.  `%d' and `%i'
  2922.           are synonymous for output, but are different when used with
  2923.           `scanf' for input (*note Standard Formatted Input::.).
  2924.  
  2925.     `o'
  2926.           Print an integer as an unsigned octal number.
  2927.  
  2928.     `u'
  2929.           Print an integer as an unsigned decimal number.
  2930.  
  2931.     `x', `X'
  2932.           Print an integer as an unsigned hexadecimal number.  `%x'
  2933.           prints using the digits `0123456789abcdef'.  `%X' prints
  2934.           using the digits `0123456789ABCDEF'.
  2935.  
  2936. Inexact Conversions
  2937. ...................
  2938.  
  2939.     `f'
  2940.           Print a floating-point number in fixed-point notation.
  2941.  
  2942.     `e', `E'
  2943.           Print a floating-point number in exponential notation.  `%e'
  2944.           prints `e' between mantissa and exponont.  `%E' prints `E'
  2945.           between mantissa and exponont.
  2946.  
  2947.     `g', `G'
  2948.           Print a floating-point number in either fixed or exponential
  2949.           notation, whichever is more appropriate for its magnitude.
  2950.           Unless an `#' flag has been supplied trailing zeros after a
  2951.           decimal point will be stripped off. `%g' prints `e' between
  2952.           mantissa and exponont.  `%G' prints `E' between mantissa and
  2953.           exponent.
  2954.  
  2955.     `k', `K'                                                                  |
  2956.           Print a number like `%g', except that an SI prefix is output        |
  2957.           after the number, which is scaled accordingly.  `%K' outputs        |
  2958.           a space between number and prefix, `%k' does not.                   |
  2959.                                                                               |
  2960. Other Conversions
  2961. .................
  2962.  
  2963.     `c'
  2964.           Print a single character.  The `-' flag is the only one which
  2965.           can be specified.  It is an error to specify a precision.
  2966.  
  2967.     `s'
  2968.           Print a string.  The `-' flag is the only one which can be
  2969.           specified.  A precision specifies the maximum number of
  2970.           characters to output; otherwise all characters in the string
  2971.           are output.
  2972.  
  2973.     `a', `A'
  2974.           Print a scheme expression.  The `-' flag left-justifies the
  2975.           output.  The `#' flag specifies that strings and characters
  2976.           should be quoted as by `write' (which can be read using
  2977.           `read'); otherwise, output is as `display' prints.  A
  2978.           precision specifies the maximum number of characters to
  2979.           output; otherwise as many characters as needed are output.
  2980.  
  2981.           *Note:* `%a' and `%A' are SLIB extensions.
  2982.  
  2983.     `%'
  2984.           Print a literal `%' character.  No argument is consumed.  It
  2985.           is an error to specifiy flags, field width, precision, or
  2986.           type modifiers with `%%'.
  2987.  
  2988. 
  2989. File: slib.info,  Node: Standard Formatted Input,  Prev: Standard Formatted Output,  Up: Standard Formatted I/O
  2990.  
  2991. Standard Formatted Input
  2992. ------------------------
  2993.  
  2994.   `(require 'scanf)'
  2995.  
  2996.  - Function: scanf-read-list FORMAT
  2997.  - Function: scanf-read-list FORMAT PORT
  2998.  - Function: scanf-read-list FORMAT STRING
  2999.  
  3000.  - Macro: scanf FORMAT ARG1 ...
  3001.  - Macro: fscanf PORT FORMAT ARG1 ...
  3002.  - Macro: sscanf STR FORMAT ARG1 ...
  3003.      Each function reads characters, interpreting them according to the
  3004.      control string FORMAT argument.
  3005.  
  3006.      `scanf-read-list' returns a list of the items specified as far as
  3007.      the input matches FORMAT.  `scanf', `fscanf', and `sscanf' return
  3008.      the number of items successfully matched and stored.  `scanf',
  3009.      `fscanf', and `sscanf' also set the location corresponding to ARG1
  3010.      ... using the methods:
  3011.  
  3012.     symbol
  3013.           `set!'
  3014.  
  3015.     car expression
  3016.           `set-car!'
  3017.  
  3018.     cdr expression
  3019.           `set-cdr!'
  3020.  
  3021.     vector-ref expression
  3022.           `vector-set!'
  3023.  
  3024.     substring expression
  3025.           `substring-move-left!'
  3026.  
  3027.      The argument to a `substring' expression in ARG1 ... must be a
  3028.      non-constant string.  Characters will be stored starting at the
  3029.      position specified by the second argument to `substring'.  The
  3030.      number of characters stored will be limited by either the position
  3031.      specified by the third argument to `substring' or the length of the
  3032.      matched string, whichever is less.
  3033.  
  3034.      The control string, FORMAT, contains conversion specifications and
  3035.      other characters used to direct interpretation of input sequences.
  3036.      The control string contains:
  3037.  
  3038.         * White-space characters (blanks, tabs, newlines, or formfeeds)
  3039.           that cause input to be read (and discarded) up to the next
  3040.           non-white-space character.
  3041.  
  3042.         * An ordinary character (not `%') that must match the next
  3043.           character of the input stream.
  3044.  
  3045.         * Conversion specifications, consisting of the character `%', an
  3046.           optional assignment suppressing character `*', an optional
  3047.           numerical maximum-field width, an optional `l', `h' or `L'
  3048.           which is ignored, and a conversion code.
  3049.  
  3050.      Unless the specification contains the `n' conversion character
  3051.      (described below), a conversion specification directs the
  3052.      conversion of the next input field.  The result of a conversion
  3053.      specification is returned in the position of the corresponding
  3054.      argument points, unless `*' indicates assignment suppression.
  3055.      Assignment suppression provides a way to describe an input field
  3056.      to be skipped.  An input field is defined as a string of
  3057.      characters; it extends to the next inappropriate character or
  3058.      until the field width, if specified, is exhausted.
  3059.  
  3060.           *Note:* This specification of format strings differs from the
  3061.           `ANSI C' and `POSIX' specifications.  In SLIB, white space
  3062.           before an input field is not skipped unless white space
  3063.           appears before the conversion specification in the format
  3064.           string.  In order to write format strings which work
  3065.           identically with `ANSI C' and SLIB, prepend whitespace to all
  3066.           conversion specifications except `[' and `c'.
  3067.  
  3068.      The conversion code indicates the interpretation of the input
  3069.      field; For a suppressed field, no value is returned.  The
  3070.      following conversion codes are legal:
  3071.  
  3072.     `%'
  3073.           A single % is expected in the input at this point; no value
  3074.           is returned.
  3075.  
  3076.     `d', `D'
  3077.           A decimal integer is expected.
  3078.  
  3079.     `u', `U'
  3080.           An unsigned decimal integer is expected.
  3081.  
  3082.     `o', `O'
  3083.           An octal integer is expected.
  3084.  
  3085.     `x', `X'
  3086.           A hexadecimal integer is expected.
  3087.  
  3088.     `i'
  3089.           An integer is expected.  Returns the value of the next input
  3090.           item, interpreted according to C conventions; a leading `0'
  3091.           implies octal, a leading `0x' implies hexadecimal; otherwise,
  3092.           decimal is assumed.
  3093.  
  3094.     `n'
  3095.           Returns the total number of bytes (including white space)
  3096.           read by `scanf'.  No input is consumed by `%n'.
  3097.  
  3098.     `f', `F', `e', `E', `g', `G'
  3099.           A floating-point number is expected.  The input format for
  3100.           floating-point numbers is an optionally signed string of
  3101.           digits, possibly containing a radix character `.', followed
  3102.           by an optional exponent field consisting of an `E' or an `e',
  3103.           followed by an optional `+', `-', or space, followed by an
  3104.           integer.
  3105.  
  3106.     `c', `C'
  3107.           WIDTH characters are expected.  The normal
  3108.           skip-over-white-space is suppressed in this case; to read the
  3109.           next non-space character, use `%1s'.  If a field width is
  3110.           given, a string is returned; up to the indicated number of
  3111.           characters is read.
  3112.  
  3113.     `s', `S'
  3114.           A character string is expected The input field is terminated
  3115.           by a white-space character.  `scanf' cannot read a null
  3116.           string.
  3117.  
  3118.     `['
  3119.           Indicates string data and the normal
  3120.           skip-over-leading-white-space is suppressed.  The left
  3121.           bracket is followed by a set of characters, called the
  3122.           scanset, and a right bracket; the input field is the maximal
  3123.           sequence of input characters consisting entirely of
  3124.           characters in the scanset.  `^', when it appears as the first
  3125.           character in the scanset, serves as a complement operator and
  3126.           redefines the scanset as the set of all characters not
  3127.           contained in the remainder of the scanset string.
  3128.           Construction of the scanset follows certain conventions.  A
  3129.           range of characters may be represented by the construct
  3130.           first-last, enabling `[0123456789]' to be expressed `[0-9]'.
  3131.           Using this convention, first must be lexically less than or
  3132.           equal to last; otherwise, the dash stands for itself.  The
  3133.           dash also stands for itself when it is the first or the last
  3134.           character in the scanset.  To include the right square
  3135.           bracket as an element of the scanset, it must appear as the
  3136.           first character (possibly preceded by a `^') of the scanset,
  3137.           in which case it will not be interpreted syntactically as the
  3138.           closing bracket.  At least one character must match for this
  3139.           conversion to succeed.
  3140.  
  3141.      The `scanf' functions terminate their conversions at end-of-file,
  3142.      at the end of the control string, or when an input character
  3143.      conflicts with the control string.  In the latter case, the
  3144.      offending character is left unread in the input stream.
  3145.  
  3146. 
  3147. File: slib.info,  Node: Programs and Arguments,  Next: HTML HTTP and CGI,  Prev: Standard Formatted I/O,  Up: Textual Conversion Packages
  3148.  
  3149. Program and Arguments
  3150. =====================
  3151.  
  3152. * Menu:
  3153.  
  3154. * Getopt::                      Command Line option parsing
  3155. * Command Line::                A command line reader for Scheme shells
  3156. * Parameter lists::             'parameters
  3157. * Getopt Parameter lists::      'getopt-parameters
  3158. * Filenames::                   'glob or 'filename
  3159. * Batch::                       'batch
  3160.  
  3161. 
  3162. File: slib.info,  Node: Getopt,  Next: Command Line,  Prev: Programs and Arguments,  Up: Programs and Arguments
  3163.  
  3164. Getopt
  3165. ------
  3166.  
  3167.   `(require 'getopt)'
  3168.  
  3169.   This routine implements Posix command line argument parsing.  Notice
  3170. that returning values through global variables means that `getopt' is
  3171. *not* reentrant.
  3172.  
  3173.  - Variable: *optind*
  3174.      Is the index of the current element of the command line.  It is
  3175.      initially one.  In order to parse a new command line or reparse an
  3176.      old one, *OPTING* must be reset.
  3177.  
  3178.  - Variable: *optarg*
  3179.      Is set by getopt to the (string) option-argument of the current
  3180.      option.
  3181.  
  3182.  - Procedure: getopt ARGC ARGV OPTSTRING
  3183.      Returns the next option letter in ARGV (starting from `(vector-ref
  3184.      argv *optind*)') that matches a letter in OPTSTRING.  ARGV is a
  3185.      vector or list of strings, the 0th of which getopt usually
  3186.      ignores. ARGC is the argument count, usually the length of ARGV.
  3187.      OPTSTRING is a string of recognized option characters; if a
  3188.      character is followed by a colon, the option takes an argument
  3189.      which may be immediately following it in the string or in the next
  3190.      element of ARGV.
  3191.  
  3192.      *OPTIND* is the index of the next element of the ARGV vector to be
  3193.      processed.  It is initialized to 1 by `getopt.scm', and `getopt'
  3194.      updates it when it finishes with each element of ARGV.
  3195.  
  3196.      `getopt' returns the next option character from ARGV that matches
  3197.      a character in OPTSTRING, if there is one that matches.  If the
  3198.      option takes an argument, `getopt' sets the variable *OPTARG* to
  3199.      the option-argument as follows:
  3200.  
  3201.         * If the option was the last character in the string pointed to
  3202.           by an element of ARGV, then *OPTARG* contains the next
  3203.           element of ARGV, and *OPTIND* is incremented by 2.  If the
  3204.           resulting value of *OPTIND* is greater than or equal to ARGC,
  3205.           this indicates a missing option argument, and `getopt'
  3206.           returns an error indication.
  3207.  
  3208.         * Otherwise, *OPTARG* is set to the string following the option
  3209.           character in that element of ARGV, and *OPTIND* is
  3210.           incremented by 1.
  3211.  
  3212.      If, when `getopt' is called, the string `(vector-ref argv
  3213.      *optind*)' either does not begin with the character `#\-' or is
  3214.      just `"-"', `getopt' returns `#f' without changing *OPTIND*.  If
  3215.      `(vector-ref argv *optind*)' is the string `"--"', `getopt'
  3216.      returns `#f' after incrementing *OPTIND*.
  3217.  
  3218.      If `getopt' encounters an option character that is not contained in
  3219.      OPTSTRING, it returns the question-mark `#\?' character.  If it
  3220.      detects a missing option argument, it returns the colon character
  3221.      `#\:' if the first character of OPTSTRING was a colon, or a
  3222.      question-mark character otherwise.  In either case, `getopt' sets
  3223.      the variable GETOPT:OPT to the option character that caused the
  3224.      error.
  3225.  
  3226.      The special option `"--"' can be used to delimit the end of the
  3227.      options; `#f' is returned, and `"--"' is skipped.
  3228.  
  3229.      RETURN VALUE
  3230.  
  3231.      `getopt' returns the next option character specified on the command
  3232.      line.  A colon `#\:' is returned if `getopt' detects a missing
  3233.      argument and the first character of OPTSTRING was a colon `#\:'.
  3234.  
  3235.      A question-mark `#\?' is returned if `getopt' encounters an option
  3236.      character not in OPTSTRING or detects a missing argument and the
  3237.      first character of OPTSTRING was not a colon `#\:'.
  3238.  
  3239.      Otherwise, `getopt' returns `#f' when all command line options
  3240.      have been parsed.
  3241.  
  3242.      Example:
  3243.           #! /usr/local/bin/scm
  3244.           ;;;This code is SCM specific.
  3245.           (define argv (program-arguments))
  3246.           (require 'getopt)
  3247.           
  3248.           (define opts ":a:b:cd")
  3249.           (let loop ((opt (getopt (length argv) argv opts)))
  3250.             (case opt
  3251.               ((#\a) (print "option a: " *optarg*))
  3252.               ((#\b) (print "option b: " *optarg*))
  3253.               ((#\c) (print "option c"))
  3254.               ((#\d) (print "option d"))
  3255.               ((#\?) (print "error" getopt:opt))
  3256.               ((#\:) (print "missing arg" getopt:opt))
  3257.               ((#f) (if (< *optind* (length argv))
  3258.                         (print "argv[" *optind* "]="
  3259.                                (list-ref argv *optind*)))
  3260.                     (set! *optind* (+ *optind* 1))))
  3261.             (if (< *optind* (length argv))
  3262.                 (loop (getopt (length argv) argv opts))))
  3263.           
  3264.           (slib:exit)
  3265.  
  3266. Getopt-
  3267. -------
  3268.  
  3269.  - Function: getopt- ARGC ARGV OPTSTRING
  3270.      The procedure `getopt--' is an extended version of `getopt' which
  3271.      parses "long option names" of the form `--hold-the-onions' and
  3272.      `--verbosity-level=extreme'.  `Getopt--' behaves as `getopt'
  3273.      except for non-empty options beginning with `--'.
  3274.  
  3275.      Options beginning with `--' are returned as strings rather than
  3276.      characters.  If a value is assigned (using `=') to a long option,
  3277.      `*optarg*' is set to the value.  The `=' and value are not
  3278.      returned as part of the option string.
  3279.  
  3280.      No information is passed to `getopt--' concerning which long
  3281.      options should be accepted or whether such options can take
  3282.      arguments.  If a long option did not have an argument, `*optarg'
  3283.      will be set to `#f'.  The caller is responsible for detecting and
  3284.      reporting errors.
  3285.  
  3286.           (define opts ":-:b:")
  3287.           (define argc 5)
  3288.           (define argv '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
  3289.           (define *optind* 1)
  3290.           (define *optarg* #f)
  3291.           (require 'qp)
  3292.           (do ((i 5 (+ -1 i)))
  3293.               ((zero? i))
  3294.             (define opt (getopt-- argc argv opts))
  3295.             (print *optind* opt *optarg*)))
  3296.           -|
  3297.           2 #\b "9"
  3298.           3 "f1" #f
  3299.           4 "2" ""
  3300.           5 "g3" "35234.342"
  3301.           5 #f "35234.342"
  3302.  
  3303. 
  3304. File: slib.info,  Node: Command Line,  Next: Parameter lists,  Prev: Getopt,  Up: Programs and Arguments
  3305.  
  3306. Command Line
  3307. ------------
  3308.  
  3309.   `(require 'read-command)'
  3310.  
  3311.  - Function: read-command PORT
  3312.  - Function: read-command
  3313.      `read-command' converts a "command line" into a list of strings
  3314.      suitable for parsing by `getopt'.  The syntax of command lines
  3315.      supported resembles that of popular "shell"s.  `read-command'
  3316.      updates PORT to point to the first character past the command
  3317.      delimiter.
  3318.  
  3319.      If an end of file is encountered in the input before any
  3320.      characters are found that can begin an object or comment, then an
  3321.      end of file object is returned.
  3322.  
  3323.      The PORT argument may be omitted, in which case it defaults to the
  3324.      value returned by `current-input-port'.
  3325.  
  3326.      The fields into which the command line is split are delimited by
  3327.      whitespace as defined by `char-whitespace?'.  The end of a command
  3328.      is delimited by end-of-file or unescaped semicolon (<;>) or
  3329.      <newline>.  Any character can be literally included in a field by
  3330.      escaping it with a backslach (<\>).
  3331.  
  3332.      The initial character and types of fields recognized are:
  3333.     `\'
  3334.           The next character has is taken literally and not interpreted
  3335.           as a field delimiter.  If <\> is the last character before a
  3336.           <newline>, that <newline> is just ignored.  Processing
  3337.           continues from the characters after the <newline> as though
  3338.           the backslash and <newline> were not there.
  3339.  
  3340.     `"'
  3341.           The characters up to the next unescaped <"> are taken
  3342.           literally, according to [R4RS] rules for literal strings
  3343.           (*note Strings: (r4rs)Strings.).
  3344.  
  3345.     `(', `%''
  3346.           One scheme expression is `read' starting with this character.
  3347.           The `read' expression is evaluated, converted to a string
  3348.           (using `display'), and replaces the expression in the returned
  3349.           field.
  3350.  
  3351.     `;'
  3352.           Semicolon delimits a command.  Using semicolons more than one
  3353.           command can appear on a line.  Escaped semicolons and
  3354.           semicolons inside strings do not delimit commands.
  3355.  
  3356.      The comment field differs from the previous fields in that it must
  3357.      be the first character of a command or appear after whitespace in
  3358.      order to be recognized.  <#> can be part of fields if these
  3359.      conditions are not met.  For instance, `ab#c' is just the field
  3360.      ab#c.
  3361.  
  3362.     `#'
  3363.           Introduces a comment.  The comment continues to the end of
  3364.           the line on which the semicolon appears.  Comments are
  3365.           treated as whitespace by `read-dommand-line' and backslashes
  3366.           before <newline>s in comments are also ignored.
  3367.  
  3368.  - Function: read-options-file FILENAME
  3369.      `read-options-file' converts an "options file" into a list of
  3370.      strings suitable for parsing by `getopt'.  The syntax of options
  3371.      files is the same as the syntax for command lines, except that
  3372.      <newline>s do not terminate reading (only <;> or end of file).
  3373.  
  3374.      If an end of file is encountered before any characters are found
  3375.      that can begin an object or comment, then an end of file object is
  3376.      returned.
  3377.  
  3378. 
  3379. File: slib.info,  Node: Parameter lists,  Next: Getopt Parameter lists,  Prev: Command Line,  Up: Programs and Arguments
  3380.  
  3381. Parameter lists
  3382. ---------------
  3383.  
  3384.   `(require 'parameters)'
  3385.  
  3386. Arguments to procedures in scheme are distinguished from each other by
  3387. their position in the procedure call.  This can be confusing when a
  3388. procedure takes many arguments, many of which are not often used.
  3389.  
  3390. A "parameter-list" is a way of passing named information to a
  3391. procedure.  Procedures are also defined to set unused parameters to
  3392. default values, check parameters, and combine parameter lists.
  3393.  
  3394. A PARAMETER has the form `(parameter-name value1 ...)'.  This format
  3395. allows for more than one value per parameter-name.
  3396.  
  3397. A PARAMETER-LIST is a list of PARAMETERs, each with a different
  3398. PARAMETER-NAME.
  3399.  
  3400.  - Function: make-parameter-list PARAMETER-NAMES
  3401.      Returns an empty parameter-list with slots for PARAMETER-NAMES.
  3402.  
  3403.  - Function: parameter-list-ref PARAMETER-LIST PARAMETER-NAME
  3404.      PARAMETER-NAME must name a valid slot of PARAMETER-LIST.
  3405.      `parameter-list-ref' returns the value of parameter PARAMETER-NAME
  3406.      of PARAMETER-LIST.
  3407.  
  3408.  - Procedure: adjoin-parameters! PARAMETER-LIST PARAMETER1 ...
  3409.      Returns PARAMETER-LIST with PARAMETER1 ... merged in.
  3410.  
  3411.  - Procedure: parameter-list-expand EXPANDERS PARAMETER-LIST
  3412.      EXPANDERS is a list of procedures whose order matches the order of
  3413.      the PARAMETER-NAMEs in the call to `make-parameter-list' which
  3414.      created PARAMETER-LIST.  For each non-false element of EXPANDERS
  3415.      that procedure is mapped over the corresponding parameter value
  3416.      and the returned parameter lists are merged into PARAMETER-LIST.
  3417.  
  3418.      This process is repeated until PARAMETER-LIST stops growing.  The
  3419.      value returned from `parameter-list-expand' is unspecified.
  3420.  
  3421.  - Function: fill-empty-parameters DEFAULTERS PARAMETER-LIST
  3422.      DEFAULTERS is a list of procedures whose order matches the order
  3423.      of the PARAMETER-NAMEs in the call to `make-parameter-list' which
  3424.      created PARAMETER-LIST.  `fill-empty-parameters' returns a new
  3425.      parameter-list with each empty parameter replaced with the list
  3426.      returned by calling the corresponding DEFAULTER with
  3427.      PARAMETER-LIST as its argument.
  3428.  
  3429.  - Function: check-parameters CHECKS PARAMETER-LIST
  3430.      CHECKS is a list of procedures whose order matches the order of
  3431.      the PARAMETER-NAMEs in the call to `make-parameter-list' which
  3432.      created PARAMETER-LIST.
  3433.  
  3434.      `check-parameters' returns PARAMETER-LIST if each CHECK of the
  3435.      corresponding PARAMETER-LIST returns non-false.  If some CHECK
  3436.      returns `#f' an error is signaled.
  3437.  
  3438. In the following procedures ARITIES is a list of symbols.  The elements
  3439. of `arities' can be:
  3440.  
  3441. `single'
  3442.      Requires a single parameter.
  3443.  
  3444. `optional'
  3445.      A single parameter or no parameter is acceptable.
  3446.  
  3447. `boolean'
  3448.      A single boolean parameter or zero parameters is acceptable.
  3449.  
  3450. `nary'
  3451.      Any number of parameters are acceptable.
  3452.  
  3453. `nary1'
  3454.      One or more of parameters are acceptable.
  3455.  
  3456.  - Function: parameter-list->arglist POSITIONS ARITIES TYPES
  3457.           PARAMETER-LIST
  3458.      Returns PARAMETER-LIST converted to an argument list.  Parameters
  3459.      of ARITY type `single' and `boolean' are converted to the single
  3460.      value associated with them.  The other ARITY types are converted
  3461.      to lists of the value(s) of type TYPES.
  3462.  
  3463.      POSITIONS is a list of positive integers whose order matches the
  3464.      order of the PARAMETER-NAMEs in the call to `make-parameter-list'
  3465.      which created PARAMETER-LIST.  The integers specify in which
  3466.      argument position the corresponding parameter should appear.
  3467.  
  3468. 
  3469. File: slib.info,  Node: Getopt Parameter lists,  Next: Filenames,  Prev: Parameter lists,  Up: Programs and Arguments
  3470.  
  3471. Getopt Parameter lists
  3472. ----------------------
  3473.  
  3474.   `(require 'getopt-parameters)'
  3475.  
  3476.  - Function: getopt->parameter-list ARGC ARGV OPTNAMES ARITIES TYPES
  3477.           ALIASES
  3478.      Returns ARGV converted to a parameter-list.  OPTNAMES are the
  3479.      parameter-names.  ALIASES is a list of lists of strings and
  3480.      elements of OPTNAMES.  Each of these strings which have length of
  3481.      1 will be treated as a single <-> option by `getopt'.  Longer
  3482.      strings will be treated as long-named options (*note getopt-:
  3483.      Getopt.).
  3484.  
  3485.  - Function: getopt->arglist ARGC ARGV OPTNAMES POSITIONS ARITIES TYPES
  3486.           DEFAULTERS CHECKS ALIASES
  3487.      Like `getopt->parameter-list', but converts ARGV to an
  3488.      argument-list as specified by OPTNAMES, POSITIONS, ARITIES, TYPES,
  3489.      DEFAULTERS, CHECKS, and ALIASES.
  3490.  
  3491. These `getopt' functions can be used with SLIB relational databases.
  3492. For an example, *Note make-command-server: Database Utilities.
  3493.  
  3494. If errors are encountered while processing options, directions for using
  3495. the options are printed to `current-error-port'.
  3496.  
  3497.      (begin
  3498.        (set! *optind* 1)
  3499.        (getopt->parameter-list
  3500.         2
  3501.         '("cmd" "-?")
  3502.         '(flag number symbols symbols string flag2 flag3 num2 num3)
  3503.         '(boolean optional nary1 nary single boolean boolean nary nary)
  3504.         '(boolean integer symbol symbol string boolean boolean integer integer)
  3505.         '(("flag" flag)
  3506.           ("f" flag)
  3507.           ("Flag" flag2)
  3508.           ("B" flag3)
  3509.           ("optional" number)
  3510.           ("o" number)
  3511.           ("nary1" symbols)
  3512.           ("N" symbols)
  3513.           ("nary" symbols)
  3514.           ("n" symbols)
  3515.           ("single" string)
  3516.           ("s" string)
  3517.           ("a" num2)
  3518.           ("Abs" num3))))
  3519.      -|
  3520.      Usage: cmd [OPTION ARGUMENT ...] ...
  3521.      
  3522.        -f, --flag
  3523.        -o, --optional=<number>
  3524.        -n, --nary=<symbols> ...
  3525.        -N, --nary1=<symbols> ...
  3526.        -s, --single=<string>
  3527.            --Flag
  3528.        -B
  3529.        -a        <num2> ...
  3530.            --Abs=<num3> ...
  3531.      
  3532.      ERROR: getopt->parameter-list "unrecognized option" "-?"
  3533.  
  3534. 
  3535. File: slib.info,  Node: Filenames,  Next: Batch,  Prev: Getopt Parameter lists,  Up: Programs and Arguments
  3536.  
  3537. Filenames
  3538. ---------
  3539.  
  3540.   `(require 'filename)' or `(require 'glob)'
  3541.  
  3542.  - Function: filename:match?? PATTERN
  3543.  - Function: filename:match-ci?? PATTERN
  3544.      Returns a predicate which returns a non-false value if its string
  3545.      argument matches (the string) PATTERN, false otherwise.  Filename
  3546.      matching is like "glob" expansion described the bash manpage,
  3547.      except that names beginning with `.' are matched and `/'
  3548.      characters are not treated specially.
  3549.  
  3550.      These functions interpret the following characters specially in
  3551.      PATTERN strings:
  3552.     `*'
  3553.           Matches any string, including the null string.
  3554.  
  3555.     `?'
  3556.           Matches any single character.
  3557.  
  3558.     `[...]'
  3559.           Matches any one of the enclosed characters.  A pair of
  3560.           characters separated by a minus sign (-) denotes a range; any
  3561.           character lexically between those two characters, inclusive,
  3562.           is matched.  If the first character following the `[' is a
  3563.           `!' or a `^' then any character not enclosed is matched.  A
  3564.           `-' or `]' may be matched by including it as the first or
  3565.           last character in the set.
  3566.  
  3567.  
  3568.  - Function: filename:substitute?? PATTERN TEMPLATE
  3569.  - Function: filename:substitute-ci?? PATTERN TEMPLATE
  3570.      Returns a function transforming a single string argument according
  3571.      to glob patterns PATTERN and TEMPLATE.  PATTERN and TEMPLATE must
  3572.      have the same number of wildcard specifications, which need not be
  3573.      identical.  PATTERN and TEMPLATE may have a different number of
  3574.      literal sections. If an argument to the function matches PATTERN
  3575.      in the sense of `filename:match??' then it returns a copy of
  3576.      TEMPLATE in which each wildcard specification is replaced by the
  3577.      part of the argument matched by the corresponding wildcard
  3578.      specification in PATTERN.  A `*' wildcard matches the longest
  3579.      leftmost string possible.  If the argument does not match PATTERN
  3580.      then false is returned.
  3581.  
  3582.      TEMPLATE may be a function accepting the same number of string
  3583.      arguments as there are wildcard specifications in PATTERN.  In the
  3584.      case of a match the result of applying TEMPLATE to a list of the
  3585.      substrings matched by wildcard specifications will be returned,
  3586.      otherwise TEMPLATE will not be called and `#f' will be returned.
  3587.  
  3588.           ((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
  3589.            "scm_10.html")
  3590.           => "scm5c4_10.htm"
  3591.           ((filename:substitute?? "??" "beg?mid?end") "AZ")
  3592.           => "begAmidZend"
  3593.           ((filename:substitute?? "*na*" "?NA?") "banana")
  3594.           => "banaNA"
  3595.           ((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1))) "ABZ")
  3596.           => "ZA"
  3597.  
  3598.  - Function: replace-suffix STR OLD NEW
  3599.      STR can be a string or a list of strings.  Returns a new string
  3600.      (or strings) similar to `str' but with the suffix string OLD
  3601.      removed and the suffix string NEW appended.  If the end of STR
  3602.      does not match OLD, an error is signaled.
  3603.  
  3604.           (replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
  3605.           => "/usr/local/lib/slib/batch.c"
  3606.  
  3607. 
  3608. File: slib.info,  Node: Batch,  Prev: Filenames,  Up: Programs and Arguments
  3609.  
  3610. Batch
  3611. -----
  3612.  
  3613.   `(require 'batch)'
  3614.  
  3615. The batch procedures provide a way to write and execute portable scripts
  3616. for a variety of operating systems.  Each `batch:' procedure takes as
  3617. its first argument a parameter-list (*note Parameter lists::.).  This
  3618. parameter-list argument PARMS contains named associations.  Batch
  3619. currently uses 2 of these:
  3620.  
  3621. `batch-port'
  3622.      The port on which to write lines of the batch file.
  3623.  
  3624. `batch-dialect'
  3625.      The syntax of batch file to generate.  Currently supported are:
  3626.         * unix
  3627.  
  3628.         * dos
  3629.  
  3630.         * vms
  3631.  
  3632.         * amigados
  3633.  
  3634.         * system
  3635.  
  3636.         * *unknown*
  3637.  
  3638. `batch.scm' uses 2 enhanced relational tables (*note Database
  3639. Utilities::.) to store information linking the names of
  3640. `operating-system's to `batch-dialect'es.
  3641.  
  3642.  - Function: batch:initialize! DATABASE
  3643.      Defines `operating-system' and `batch-dialect' tables and adds the
  3644.      domain `operating-system' to the enhanced relational database
  3645.      DATABASE.
  3646.  
  3647.  - Variable: batch:platform
  3648.      Is batch's best guess as to which operating-system it is running
  3649.      under.  `batch:platform' is set to `(software-type)' (*note
  3650.      Configuration::.) unless `(software-type)' is `unix', in which
  3651.      case finer distinctions are made.
  3652.  
  3653.  - Function: batch:call-with-output-script PARMS FILE PROC
  3654.      PROC should be a procedure of one argument.  If FILE is an
  3655.      output-port, `batch:call-with-output-script' writes an appropriate
  3656.      header to FILE and then calls PROC with FILE as the only argument.
  3657.      If FILE is a string, `batch:call-with-output-script' opens a
  3658.      output-file of name FILE, writes an appropriate header to FILE,
  3659.      and then calls PROC with the newly opened port as the only
  3660.      argument.  Otherwise, `batch:call-with-output-script' acts as if
  3661.      it was called with the result of `(current-output-port)' as its
  3662.      third argument.
  3663.  
  3664. The rest of the `batch:' procedures write (or execute if
  3665. `batch-dialect' is `system') commands to the batch port which has been
  3666. added to PARMS or `(copy-tree PARMS)' by the code:
  3667.  
  3668.      (adjoin-parameters! PARMS (list 'batch-port PORT))
  3669.  
  3670.  - Function: batch:command PARMS STRING1 STRING2 ...
  3671.      Calls `batch:try-command' (below) with arguments, but signals an
  3672.      error if `batch:try-command' returns `#f'.
  3673.  
  3674. These functions return a non-false value if the command was successfully
  3675. translated into the batch dialect and `#f' if not.  In the case of the
  3676. `system' dialect, the value is non-false if the operation suceeded.
  3677.  
  3678.  - Function: batch:try-command PARMS STRING1 STRING2 ...
  3679.      Writes a command to the `batch-port' in PARMS which executes the
  3680.      program named STRING1 with arguments STRING2 ....
  3681.  
  3682.  - Function: batch:try-chopped-command PARMS ARG1 ARG2 ... LIST
  3683.      breaks the last argument LIST into chunks small enough so that the
  3684.      command:
  3685.  
  3686.           ARG1 ARG2 ... CHUNK
  3687.  
  3688.      fits withing the platform's maximum command-line length.
  3689.  
  3690.      `batch:try-chopped-command' calls `batch:try-command' with the
  3691.      command and returns non-false only if the commands all fit and
  3692.      `batch:try-command' of each command line returned non-false.
  3693.  
  3694.  - Function: batch:run-script PARMS STRING1 STRING2 ...
  3695.      Writes a command to the `batch-port' in PARMS which executes the
  3696.      batch script named STRING1 with arguments STRING2 ....
  3697.  
  3698.      *Note:* `batch:run-script' and `batch:try-command' are not the
  3699.      same for some operating systems (VMS).
  3700.  
  3701.  - Function: batch:comment PARMS LINE1 ...
  3702.      Writes comment lines LINE1 ... to the `batch-port' in PARMS.
  3703.  
  3704.  - Function: batch:lines->file PARMS FILE LINE1 ...
  3705.      Writes commands to the `batch-port' in PARMS which create a file
  3706.      named FILE with contents LINE1 ....
  3707.  
  3708.  - Function: batch:delete-file PARMS FILE
  3709.      Writes a command to the `batch-port' in PARMS which deletes the
  3710.      file named FILE.
  3711.  
  3712.  - Function: batch:rename-file PARMS OLD-NAME NEW-NAME
  3713.      Writes a command to the `batch-port' in PARMS which renames the
  3714.      file OLD-NAME to NEW-NAME.
  3715.  
  3716. In addition, batch provides some small utilities very useful for writing
  3717. scripts:
  3718.  
  3719.  - Function: truncate-up-to PATH CHAR
  3720.  - Function: truncate-up-to PATH STRING
  3721.  - Function: truncate-up-to PATH CHARLIST
  3722.      PATH can be a string or a list of strings.  Returns PATH sans any
  3723.      prefixes ending with a character of the second argument.  This can
  3724.      be used to derive a filename moved locally from elsewhere.
  3725.  
  3726.           (truncate-up-to "/usr/local/lib/slib/batch.scm" "/")
  3727.           => "batch.scm"
  3728.  
  3729.  - Function: string-join JOINER STRING1 ...
  3730.      Returns a new string consisting of all the strings STRING1 ...  in
  3731.      order appended together with the string JOINER between each
  3732.      adjacent pair.
  3733.  
  3734.  - Function: must-be-first LIST1 LIST2
  3735.      Returns a new list consisting of the elements of LIST2 ordered so
  3736.      that if some elements of LIST1 are `equal?' to elements of LIST2,
  3737.      then those elements will appear first and in the order of LIST1.
  3738.  
  3739.  - Function: must-be-last LIST1 LIST2
  3740.      Returns a new list consisting of the elements of LIST1 ordered so
  3741.      that if some elements of LIST2 are `equal?' to elements of LIST1,
  3742.      then those elements will appear last and in the order of LIST2.
  3743.  
  3744.  - Function: os->batch-dialect OSNAME
  3745.      Returns its best guess for the `batch-dialect' to be used for the
  3746.      operating-system named OSNAME.  `os->batch-dialect' uses the
  3747.      tables added to DATABASE by `batch:initialize!'.
  3748.  
  3749. Here is an example of the use of most of batch's procedures:
  3750.  
  3751.      (require 'database-utilities)
  3752.      (require 'parameters)
  3753.      (require 'batch)
  3754.      (require 'glob)
  3755.      
  3756.      (define batch (create-database #f 'alist-table))
  3757.      (batch:initialize! batch)
  3758.      
  3759.      (define my-parameters
  3760.        (list (list 'batch-dialect (os->batch-dialect batch:platform))
  3761.              (list 'platform batch:platform)
  3762.              (list 'batch-port (current-output-port)))) ;gets filled in later
  3763.      
  3764.      (batch:call-with-output-script
  3765.       my-parameters
  3766.       "my-batch"
  3767.       (lambda (batch-port)
  3768.         (adjoin-parameters! my-parameters (list 'batch-port batch-port))
  3769.         (and
  3770.          (batch:comment my-parameters
  3771.                         "================ Write file with C program.")
  3772.          (batch:rename-file my-parameters "hello.c" "hello.c~")
  3773.          (batch:lines->file my-parameters "hello.c"
  3774.                             "#include <stdio.h>"
  3775.                             "int main(int argc, char **argv)"
  3776.                             "{"
  3777.                             "  printf(\"hello world\\n\");"
  3778.                             "  return 0;"
  3779.                             "}" )
  3780.          (batch:command my-parameters "cc" "-c" "hello.c")
  3781.          (batch:command my-parameters "cc" "-o" "hello"
  3782.                        (replace-suffix "hello.c" ".c" ".o"))
  3783.          (batch:command my-parameters "hello")
  3784.          (batch:delete-file my-parameters "hello")
  3785.          (batch:delete-file my-parameters "hello.c")
  3786.          (batch:delete-file my-parameters "hello.o")
  3787.          (batch:delete-file my-parameters "my-batch")
  3788.          )))
  3789.  
  3790. Produces the file `my-batch':
  3791.  
  3792.      #!/bin/sh
  3793.      # "my-batch" script created by SLIB/batch Sun Oct 31 18:24:10 1999
  3794.      # ================ Write file with C program.
  3795.      mv -f hello.c hello.c~
  3796.      rm -f hello.c
  3797.      echo '#include <stdio.h>'>>hello.c
  3798.      echo 'int main(int argc, char **argv)'>>hello.c
  3799.      echo '{'>>hello.c
  3800.      echo '  printf("hello world\n");'>>hello.c
  3801.      echo '  return 0;'>>hello.c
  3802.      echo '}'>>hello.c
  3803.      cc -c hello.c
  3804.      cc -o hello hello.o
  3805.      hello
  3806.      rm -f hello
  3807.      rm -f hello.c
  3808.      rm -f hello.o
  3809.      rm -f my-batch
  3810.  
  3811. When run, `my-batch' prints:
  3812.  
  3813.      bash$ my-batch
  3814.      mv: hello.c: No such file or directory
  3815.      hello world
  3816.  
  3817. 
  3818. File: slib.info,  Node: HTML HTTP and CGI,  Next: Printing Scheme,  Prev: Programs and Arguments,  Up: Textual Conversion Packages
  3819.  
  3820. HTML HTTP and CGI                                                             |
  3821. =================                                                             |
  3822.  
  3823.   `(require 'html-form)'
  3824.  
  3825.  - Variable: *html:output-port*
  3826.      Procedure names starting with `html:' send their output to the
  3827.      port *HTML:OUTPUT-PORT*.  *HTML:OUTPUT-PORT* is initially the
  3828.      current output port.
  3829.  
  3830.  - Function: make-atval TXT
  3831.      Returns a string with character substitutions appropriate to send
  3832.      TXT as an "attribute-value".
  3833.  
  3834.  - Function: make-plain TXT
  3835.      Returns a string with character substitutions appropriate to send
  3836.      TXT as an "plain-text".
  3837.  
  3838.  - Function: html:start-page TITLE BACKLINK TAGS ...
  3839.  - Function: html:start-page TITLE BACKLINK
  3840.  - Function: html:start-page TITLE
  3841.      Outputs headers for an HTML page named TITLE.  If string arguments
  3842.      BACKLINK ... are supplied they are printed verbatim within the
  3843.      <HEAD> section.
  3844.  
  3845.  - Function: html:end-page
  3846.      Outputs HTML codes to end a page.
  3847.  
  3848.  - Function: html:pre LINE1 LINE ...
  3849.      Writes (using `html:printf') the strings LINE1, LINES as
  3850.      "PRE"formmated plain text (rendered in fixed-width font).
  3851.      Newlines are inserted between LINE1, LINES.  HTML tags (`<tag>')
  3852.      within LINES will be visible verbatim.
  3853.  
  3854.  - Function: html:comment LINE1 LINE ...
  3855.      Writes (using `html:printf') the strings LINE1 as HTML comments.
  3856.  
  3857. HTML Tables
  3858. ===========
  3859.  
  3860.  - Function: html:start-table CAPTION
  3861.  
  3862.  - Function: html:end-table
  3863.  
  3864.  - Function: html:heading COLUMNS
  3865.      Outputs a heading row for the currently-started table.
  3866.  
  3867.  - Function: html:href-heading COLUMNS URLS
  3868.      Outputs a heading row with column-names COLUMNS linked to URLs
  3869.      URLS.
  3870.  
  3871.  - Function: make-row-converter K FOREIGNS
  3872.      The positive integer K is the primary-key-limit (number of
  3873.      primary-keys) of the table.  FOREIGNS is a list of the filenames of
  3874.      foreign-key field pages and #f for non foreign-key fields.
  3875.  
  3876.      `make-row-converter' returns a procedure taking a row for its
  3877.      single argument.  This returned procedure prints the table row to
  3878.      *HTML:OUTPUT-PORT*.
  3879.  
  3880.  - Function: table-name->filename TABLE-NAME
  3881.      Returns the symbol TABLE-NAME converted to a filename.
  3882.  
  3883.  - Function: table->html CAPTION DB TABLE-NAME MATCH-KEY1 ...
  3884.      Writes HTML for DB table TABLE-NAME to *HTML:OUTPUT-PORT*.
  3885.  
  3886.      The optional MATCH-KEY1 ... arguments restrict actions to a subset
  3887.      of the table.  *Note match-key: Table Operations.
  3888.  
  3889.  - Function: table->page DB TABLE-NAME INDEX-FILENAME
  3890.      Writes a complete HTML page to *HTML:OUTPUT-PORT*.  The string
  3891.      INDEX-FILENAME names the page which refers to this one.
  3892.  
  3893.  - Function: catalog->html DB CAPTION
  3894.      Writes HTML for the catalog table of DB to *HTML:OUTPUT-PORT*.
  3895.  
  3896.  - Function: catalog->page DB CAPTION
  3897.      Writes a complete HTML page for the catalog of DB to
  3898.      *HTML:OUTPUT-PORT*.
  3899.  
  3900. HTML Forms
  3901. ==========
  3902.  
  3903.  - Function: html:start-form METHOD ACTION
  3904.      The symbol METHOD is either `get', `head', `post', `put', or
  3905.      `delete'.  `html:start-form' prints the header for an HTML "form".
  3906.  
  3907.  - Function: html:end-form PNAME SUBMIT-LABEL
  3908.      `html:end-form' prints the footer for an HTML "form".  The string
  3909.      SUBMIT-LABEL appears on the button which submits the form.
  3910.  
  3911.  - Function: command->html RDB COMMAND-TABLE COMMAND METHOD ACTION
  3912.      The symbol COMMAND-TABLE names a command table in the RDB
  3913.      relational database.
  3914.  
  3915.      `command->html' writes an HTML-2.0 "form" for command COMMAND to
  3916.      the current-output-port.  The `SUBMIT' button, which is labeled
  3917.      COMMAND, invokes the URI ACTION with method METHOD with a hidden
  3918.      attribute `*command*' bound to the command symbol submitted.
  3919.  
  3920.      An action may invoke a CGI script
  3921.      (`http://www.my-site.edu/cgi-bin/search.cgi') or HTTP daemon
  3922.      (`http://www.my-site.edu:8001').
  3923.  
  3924.      This example demonstrates how to create a HTML-form for the `build'
  3925.      command.
  3926.  
  3927.           (require (in-vicinity (implementation-vicinity) "build.scm"))
  3928.           (call-with-output-file "buildscm.html"
  3929.             (lambda (port)
  3930.               (fluid-let ((*html:output-port* port))
  3931.                 (html:start-page 'commands)
  3932.                 (command->html
  3933.                  build '*commands* 'build 'post
  3934.                  (or "/cgi-bin/build.cgi"
  3935.                      "http://localhost:8081/buildscm"))
  3936.                 html:end-page)))
  3937.  
  3938. HTTP and CGI service
  3939. ====================
  3940.  
  3941.   `(require 'html-form)'
  3942.  
  3943.  - Function: cgi:serve-command RDB COMMAND-TABLE
  3944.      Reads a `"POST"' or `"GET"' query from `(current-input-port)' and
  3945.      executes the encoded command from COMMAND-TABLE in
  3946.      relational-database RDB.
  3947.  
  3948.      This example puts up a plain-text page in response to a CGI query.
  3949.  
  3950.           (display "Content-Type: text/plain") (newline) (newline)
  3951.           (require 'html-form)
  3952.           (load (in-vicinity (implementation-vicinity) "build.scm"))
  3953.           (cgi:serve-command build '*commands*)
  3954.  
  3955.  - Function: serve-urlencoded-command RDB COMMAND-TABLE URLENCODED
  3956.      Reads attribute-value pairs from URLENCODED, converts them to
  3957.      parameters and invokes the RDB command named by the parameter
  3958.      `*command*'.
  3959.  
  3960.  - Function: http:serve-uri INPUT-PORT OUTPUT-PORT SERVE-PROC                 |
  3961.      reads the "URI" from INPUT-PORT.  If this is a valid URI, then           |
  3962.      `http:serve-uri' calls SERVE-PROC with three arguments, the              |
  3963.      request string, INPUT-PORT and OUTPUT-PORT.                              |
  3964.                                                                               |
  3965.      Otherwise, `http:serve-uri' replies (to OUTPUT-PORT) with                |
  3966.      appropriate HTML describing the problem.                                 |
  3967.                                                                               |
  3968.  - Function: http:serve-query INPUT-PORT OUTPUT-PORT SERVE-PROC
  3969.      reads the "query-string" from INPUT-PORT.  If this is a valid
  3970.      `"POST"' or `"GET"' query, then `http:serve-query' calls
  3971.      SERVE-PROC with two arguments, the query-string and the
  3972.      header-alist.
  3973.  
  3974.      Otherwise, `http:serve-query' replies (to OUTPUT-PORT) with
  3975.      appropriate HTML describing the problem.
  3976.   This example services HTTP queries from port 8081:
  3977.  
  3978.      (define socket (make-stream-socket AF_INET 0))
  3979.      (socket:bind socket 8081)
  3980.      (socket:listen socket 10)
  3981.      (dynamic-wind
  3982.       (lambda () #f)
  3983.       (lambda ()
  3984.         (do ((port (socket:accept socket)
  3985.                    (socket:accept socket)))
  3986.             (#f)
  3987.           (dynamic-wind
  3988.            (lambda () #f)
  3989.            (lambda ()
  3990.              (fluid-let ((*html:output-port* port))
  3991.                (http:serve-query
  3992.                 port port
  3993.                 (lambda (query-string header)
  3994.                   (http:send-header
  3995.                    '(("Content-Type" . "text/plain")))
  3996.                   (with-output-to-port port
  3997.                     (lambda ()
  3998.                       (serve-urlencoded-command
  3999.                        build '*commands* query-string)))))))
  4000.            (lambda () (close-port port)))))
  4001.       (lambda () (close-port socket)))
  4002.  
  4003.  - Function: http:read-request-line PORT
  4004.      Reads the first non-blank line from PORT and, if successful,
  4005.      returns a list of three itmes from the request-line:
  4006.  
  4007.        0. Method
  4008.  
  4009.           Either one of the symbols `options', `get', `head', `post',
  4010.           `put', `delete', or `trace'; Or a string.
  4011.  
  4012.        1. Request-URI
  4013.  
  4014.           A string.  At the minimum, it will be the string `"/"'.
  4015.  
  4016.        2. HTTP-Version
  4017.  
  4018.           A string.  For example, `HTTP/1.0'.
  4019.  
  4020.  - Function: cgi:read-query-string
  4021.      Reads the "query-string" from `(current-input-port)'.
  4022.      `cgi:read-query-string' reads a `"POST"' or `"GET"' queries,
  4023.      depending on the value of `(getenv "REQUEST_METHOD")'.
  4024.  
  4025. HTML databases                                                                |
  4026. --------------                                                                |
  4027.                                                                               |
  4028.   `(require 'db->html)'                                                       |
  4029.                                                                               |
  4030.  - Function: db->files DB DIR INDEX-FILENAME CAPTION                          |
  4031.      DB must be a relational database.  DIR must be #f or a non-empty         |
  4032.      string naming an existing sub-directory of the current directory.        |
  4033.                                                                               |
  4034.      `db->files' creates an html page for each table in the database DB       |
  4035.      in the sub-directory named DIR, or the current directory if DIR is       |
  4036.      #f.  The top level page with the catalog of tables (captioned            |
  4037.      CAPTION) is written to a file named INDEX-FILENAME.                      |
  4038.                                                                               |
  4039.  - Function: db->directory DB DIR INDEX-FILENAME                              |
  4040.  - Function: db->directory DB DIR                                             |
  4041.      DB must be a relational database.  DIR must be a non-empty string        |
  4042.      naming an existing sub-directory of the current directory or one         |
  4043.      to be created.  The optional string INDEX-FILENAME names the             |
  4044.      filename of the top page, which defaults to `index.html'.                |
  4045.                                                                               |
  4046.      `db->directory' creates sub-directory DIR if neccessary, and calls       |
  4047.      `(db->files DB DIR INDEX-FILENAME DIR)'.  The `file:' URL of             |
  4048.      INDEX-FILENAME is returned.                                              |
  4049.                                                                               |
  4050.  - Function: db->netscape DB DIR INDEX-FILENAME                               |
  4051.  - Function: db->netscape DB DIR                                              |
  4052.      `db->netscape' is just like `db->directory', but calls                   |
  4053.      `browse-url-netscape' with the url for the top page after the            |
  4054.      pages are created.                                                       |
  4055.                                                                               |
  4056. 
  4057. File: slib.info,  Node: Printing Scheme,  Next: Time and Date,  Prev: HTML HTTP and CGI,  Up: Textual Conversion Packages
  4058.  
  4059. Printing Scheme
  4060. ===============
  4061.  
  4062. * Menu:
  4063.  
  4064. * Generic-Write::               'generic-write
  4065. * Object-To-String::            'object->string
  4066. * Pretty-Print::                'pretty-print, 'pprint-file
  4067.  
  4068. 
  4069. File: slib.info,  Node: Generic-Write,  Next: Object-To-String,  Prev: Printing Scheme,  Up: Printing Scheme
  4070.  
  4071. Generic-Write
  4072. -------------
  4073.  
  4074.   `(require 'generic-write)'
  4075.  
  4076.   `generic-write' is a procedure that transforms a Scheme data value
  4077. (or Scheme program expression) into its textual representation and
  4078. prints it.  The interface to the procedure is sufficiently general to
  4079. easily implement other useful formatting procedures such as pretty
  4080. printing, output to a string and truncated output.
  4081.  
  4082.  - Procedure: generic-write OBJ DISPLAY? WIDTH OUTPUT
  4083.     OBJ
  4084.           Scheme data value to transform.
  4085.  
  4086.     DISPLAY?
  4087.           Boolean, controls whether characters and strings are quoted.
  4088.  
  4089.     WIDTH
  4090.           Extended boolean, selects format:
  4091.          #f
  4092.                single line format
  4093.  
  4094.          integer > 0
  4095.                pretty-print (value = max nb of chars per line)
  4096.  
  4097.     OUTPUT
  4098.           Procedure of 1 argument of string type, called repeatedly with
  4099.           successive substrings of the textual representation.  This
  4100.           procedure can return `#f' to stop the transformation.
  4101.  
  4102.      The value returned by `generic-write' is undefined.
  4103.  
  4104.      Examples:
  4105.           (write obj) == (generic-write obj #f #f DISPLAY-STRING)
  4106.           (display obj) == (generic-write obj #t #f DISPLAY-STRING)
  4107.  
  4108.      where
  4109.           DISPLAY-STRING ==
  4110.           (lambda (s) (for-each write-char (string->list s)) #t)
  4111.  
  4112. 
  4113. File: slib.info,  Node: Object-To-String,  Next: Pretty-Print,  Prev: Generic-Write,  Up: Printing Scheme
  4114.  
  4115. Object-To-String
  4116. ----------------
  4117.  
  4118.   `(require 'object->string)'
  4119.  
  4120.  - Function: object->string OBJ
  4121.      Returns the textual representation of OBJ as a string.
  4122.  
  4123.  - Function: object->limited-string OBJ LIMIT
  4124.      Returns the textual representation of OBJ as a string of length at
  4125.      most LIMIT.
  4126.  
  4127. 
  4128. File: slib.info,  Node: Pretty-Print,  Prev: Object-To-String,  Up: Printing Scheme
  4129.  
  4130. Pretty-Print
  4131. ------------
  4132.  
  4133.   `(require 'pretty-print)'
  4134.  
  4135.  - Procedure: pretty-print OBJ
  4136.  - Procedure: pretty-print OBJ PORT
  4137.      `pretty-print's OBJ on PORT.  If PORT is not specified,
  4138.      `current-output-port' is used.
  4139.  
  4140.      Example:
  4141.           (pretty-print '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
  4142.                           (16 17 18 19 20) (21 22 23 24 25)))
  4143.              -| ((1 2 3 4 5)
  4144.              -|  (6 7 8 9 10)
  4145.              -|  (11 12 13 14 15)
  4146.              -|  (16 17 18 19 20)
  4147.              -|  (21 22 23 24 25))
  4148.  
  4149.   `(require 'pprint-file)'
  4150.  
  4151.  - Procedure: pprint-file INFILE
  4152.  - Procedure: pprint-file INFILE OUTFILE
  4153.      Pretty-prints all the code in INFILE.  If OUTFILE is specified,
  4154.      the output goes to OUTFILE, otherwise it goes to
  4155.      `(current-output-port)'.
  4156.  
  4157.  - Function: pprint-filter-file INFILE PROC OUTFILE
  4158.  - Function: pprint-filter-file INFILE PROC
  4159.      INFILE is a port or a string naming an existing file.  Scheme
  4160.      source code expressions and definitions are read from the port (or
  4161.      file) and PROC is applied to them sequentially.
  4162.  
  4163.      OUTFILE is a port or a string.  If no OUTFILE is specified then
  4164.      `current-output-port' is assumed.  These expanded expressions are
  4165.      then `pretty-print'ed to this port.
  4166.  
  4167.      Whitepsace and comments (introduced by `;') which are not part of
  4168.      scheme expressions are reproduced in the output.  This procedure
  4169.      does not affect the values returned by `current-input-port' and
  4170.      `current-output-port'.
  4171.  
  4172.   `pprint-filter-file' can be used to pre-compile macro-expansion and
  4173. thus can reduce loading time.  The following will write into
  4174. `exp-code.scm' the result of expanding all defmacros in `code.scm'.
  4175.      (require 'pprint-file)
  4176.      (require 'defmacroexpand)
  4177.      (defmacro:load "my-macros.scm")
  4178.      (pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm")
  4179.  
  4180. 
  4181. File: slib.info,  Node: Time and Date,  Next: Vector Graphics,  Prev: Printing Scheme,  Up: Textual Conversion Packages
  4182.  
  4183. Time and Date
  4184. =============
  4185.  
  4186. * Menu:
  4187.  
  4188. * Time Zone::
  4189. * Posix Time::                  'posix-time
  4190. * Common-Lisp Time::            'common-lisp-time
  4191.  
  4192. If `(provided? 'current-time)':
  4193.  
  4194. The procedures `current-time', `difftime', and `offset-time' deal with
  4195. a "calendar time" datatype which may or may not be disjoint from other
  4196. Scheme datatypes.
  4197.  
  4198.  - Function: current-time
  4199.      Returns the time since 00:00:00 GMT, January 1, 1970, measured in
  4200.      seconds.  Note that the reference time is different from the
  4201.      reference time for `get-universal-time' in *Note Common-Lisp
  4202.      Time::.
  4203.  
  4204.  - Function: difftime CALTIME1 CALTIME0
  4205.      Returns the difference (number of seconds) between twe calendar
  4206.      times: CALTIME1 - CALTIME0.  CALTIME0 may also be a number.
  4207.  
  4208.  - Function: offset-time CALTIME OFFSET
  4209.      Returns the calendar time of CALTIME offset by OFFSET number of
  4210.      seconds `(+ caltime offset)'.
  4211.  
  4212. 
  4213. File: slib.info,  Node: Time Zone,  Next: Posix Time,  Prev: Time and Date,  Up: Time and Date
  4214.  
  4215. Time Zone
  4216. ---------
  4217.  
  4218.   (require 'time-zone)
  4219.  
  4220.  - Data Format: TZ-string
  4221.      POSIX standards specify several formats for encoding time-zone
  4222.      rules.
  4223.  
  4224.     :<pathname>
  4225.           If the first character of <pathname> is `/', then <pathname>
  4226.           specifies the absolute pathname of a tzfile(5) format
  4227.           time-zone file.  Otherwise, <pathname> is interpreted as a
  4228.           pathname within TZFILE:VICINITY (/usr/lib/zoneinfo/) naming a
  4229.           tzfile(5) format time-zone file.
  4230.  
  4231.     <std><offset>
  4232.           The string <std> consists of 3 or more alphabetic characters.
  4233.           <offset> specifies the time difference from GMT.  The <offset>
  4234.           is positive if the local time zone is west of the Prime
  4235.           Meridian and negative if it is east.  <offset> can be the
  4236.           number of hours or hours and minutes (and optionally seconds)
  4237.           separated by `:'.  For example, `-4:30'.
  4238.  
  4239.     <std><offset><dst>
  4240.           <dst> is the at least 3 alphabetic characters naming the local
  4241.           daylight-savings-time.
  4242.  
  4243.     <std><offset><dst><doffset>
  4244.           <doffset> specifies the offset from the Prime Meridian when
  4245.           daylight-savings-time is in effect.
  4246.  
  4247.      The non-tzfile formats can optionally be followed by transition
  4248.      times specifying the day and time when a zone changes from
  4249.      standard to daylight-savings and back again.
  4250.  
  4251.     ,<date>/<time>,<date>/<time>
  4252.           The <time>s are specified like the <offset>s above, except
  4253.           that leading `+' and `-' are not allowed.
  4254.  
  4255.           Each <date> has one of the formats:
  4256.  
  4257.          J<day>
  4258.                specifies the Julian day with <day> between 1 and 365.
  4259.                February 29 is never counted and cannot be referenced.
  4260.  
  4261.          <day>
  4262.                This specifies the Julian day with n between 0 and 365.
  4263.                February 29 is counted in leap years and can be
  4264.                specified.
  4265.  
  4266.          M<month>.<week>.<day>
  4267.                This specifies day <day> (0 <= <day> <= 6) of week
  4268.                <week> (1 <= <week> <= 5) of month <month> (1 <= <month>
  4269.                <= 12).  Week 1 is the first week in which day d occurs
  4270.                and week 5 is the last week in which day <day> occurs.
  4271.                Day 0 is a Sunday.
  4272.  
  4273.  
  4274.  - Data Type: time-zone
  4275.      is a datatype encoding how many hours from Greenwich Mean Time the
  4276.      local time is, and the "Daylight Savings Time" rules for changing
  4277.      it.
  4278.  
  4279.  - Function: time-zone TZ-STRING
  4280.      Creates and returns a time-zone object specified by the string
  4281.      TZ-STRING.  If `time-zone' cannot interpret TZ-STRING, `#f' is
  4282.      returned.
  4283.  
  4284.  - Function: tz:params CALTIME TZ
  4285.      TZ is a time-zone object.  `tz:params' returns a list of three
  4286.      items:
  4287.        0. An integer.  0 if standard time is in effect for timezone TZ
  4288.           at CALTIME; 1 if daylight savings time is in effect for
  4289.           timezone TZ at CALTIME.
  4290.  
  4291.        1. The number of seconds west of the Prime Meridian timezone TZ
  4292.           is at CALTIME.
  4293.  
  4294.        2. The name for timezone TZ at CALTIME.
  4295.  
  4296.      `tz:params' is unaffected by the default timezone; inquiries can be
  4297.      made of any timezone at any calendar time.
  4298.  
  4299.  
  4300. The rest of these procedures and variables are provided for POSIX
  4301. compatability.  Because of shared state they are not thread-safe.
  4302.  
  4303.  - Function: tzset
  4304.      Returns the default time-zone.
  4305.  
  4306.  - Function: tzset TZ
  4307.      Sets (and returns) the default time-zone to TZ.
  4308.  
  4309.  - Function: tzset TZ-STRING
  4310.      Sets (and returns) the default time-zone to that specified by
  4311.      TZ-STRING.
  4312.  
  4313.      `tzset' also sets the variables *TIMEZONE*, DAYLIGHT?, and TZNAME.
  4314.      This function is automatically called by the time conversion
  4315.      procedures which depend on the time zone (*note Time and Date::.).
  4316.  
  4317.  - Variable: *timezone*
  4318.      Contains the difference, in seconds, between Greenwich Mean Time
  4319.      and local standard time (for example, in the U.S.  Eastern time
  4320.      zone (EST), timezone is 5*60*60).  `*timezone*' is initialized by
  4321.      `tzset'.
  4322.  
  4323.  - Variable: daylight?
  4324.      is `#t' if the default timezone has rules for "Daylight Savings
  4325.      Time".  *Note:* DAYLIGHT? does not tell you when Daylight Savings
  4326.      Time is in effect, just that the default zone sometimes has
  4327.      Daylight Savings Time.
  4328.  
  4329.  - Variable: tzname
  4330.      is a vector of strings.  Index 0 has the abbreviation for the
  4331.      standard timezone; If DAYLIGHT?, then index 1 has the abbreviation
  4332.      for the Daylight Savings timezone.
  4333.  
  4334. 
  4335. File: slib.info,  Node: Posix Time,  Next: Common-Lisp Time,  Prev: Time Zone,  Up: Time and Date
  4336.  
  4337. Posix Time
  4338. ----------
  4339.  
  4340.      (require 'posix-time)
  4341.  
  4342.  - Data Type: Calendar-Time
  4343.      is a datatype encapsulating time.
  4344.  
  4345.  - Data Type: Coordinated Universal Time
  4346.      (abbreviated "UTC") is a vector of integers representing time:
  4347.  
  4348.        0.  seconds (0 - 61)
  4349.  
  4350.        1.  minutes (0 - 59)
  4351.  
  4352.        2.  hours since midnight (0 - 23)
  4353.  
  4354.        3.  day of month (1 - 31)
  4355.  
  4356.        4.  month (0 - 11).  Note difference from
  4357.           `decode-universal-time'.
  4358.  
  4359.        5.  the number of years since 1900.  Note difference from
  4360.           `decode-universal-time'.
  4361.  
  4362.        6.  day of week (0 - 6)
  4363.  
  4364.        7.  day of year (0 - 365)
  4365.  
  4366.        8.  1 for daylight savings, 0 for regular time
  4367.  
  4368.  - Function: gmtime CALTIME
  4369.      Converts the calendar time CALTIME to UTC and returns it.
  4370.  
  4371.  - Function: localtime CALTIME TZ
  4372.      Returns CALTIME converted to UTC relative to timezone TZ.
  4373.  
  4374.  - Function: localtime CALTIME
  4375.      converts the calendar time CALTIME to a vector of integers
  4376.      expressed relative to the user's time zone.  `localtime' sets the
  4377.      variable *TIMEZONE* with the difference between Coordinated
  4378.      Universal Time (UTC) and local standard time in seconds (*note
  4379.      tzset: Time Zone.).
  4380.  
  4381.  
  4382.  - Function: gmktime UNIVTIME
  4383.      Converts a vector of integers in GMT Coordinated Universal Time
  4384.      (UTC) format to a calendar time.
  4385.  
  4386.  - Function: mktime UNIVTIME
  4387.      Converts a vector of integers in local Coordinated Universal Time
  4388.      (UTC) format to a calendar time.
  4389.  
  4390.  - Function: mktime UNIVTIME TZ
  4391.      Converts a vector of integers in Coordinated Universal Time (UTC)
  4392.      format (relative to time-zone TZ) to calendar time.
  4393.  
  4394.  - Function: asctime UNIVTIME
  4395.      Converts the vector of integers CALTIME in Coordinated Universal
  4396.      Time (UTC) format into a string of the form `"Wed Jun 30 21:49:08
  4397.      1993"'.
  4398.  
  4399.  - Function: gtime CALTIME
  4400.  - Function: ctime CALTIME
  4401.  - Function: ctime CALTIME TZ
  4402.      Equivalent to `(asctime (gmtime CALTIME))', `(asctime (localtime
  4403.      CALTIME))', and `(asctime (localtime CALTIME TZ))', respectively.
  4404.  
  4405. 
  4406. File: slib.info,  Node: Common-Lisp Time,  Prev: Posix Time,  Up: Time and Date
  4407.  
  4408. Common-Lisp Time
  4409. ----------------
  4410.  
  4411.  - Function: get-decoded-time
  4412.      Equivalent to `(decode-universal-time (get-universal-time))'.
  4413.  
  4414.  - Function: get-universal-time
  4415.      Returns the current time as "Universal Time", number of seconds
  4416.      since 00:00:00 Jan 1, 1900 GMT.  Note that the reference time is
  4417.      different from `current-time'.
  4418.  
  4419.  - Function: decode-universal-time UNIVTIME
  4420.      Converts UNIVTIME to "Decoded Time" format.  Nine values are
  4421.      returned:
  4422.        0.  seconds (0 - 61)
  4423.  
  4424.        1.  minutes (0 - 59)
  4425.  
  4426.        2.  hours since midnight
  4427.  
  4428.        3.  day of month
  4429.  
  4430.        4.  month (1 - 12).  Note difference from `gmtime' and
  4431.           `localtime'.
  4432.  
  4433.        5.  year (A.D.).  Note difference from `gmtime' and `localtime'.
  4434.  
  4435.        6.  day of week (0 - 6)
  4436.  
  4437.        7.  #t for daylight savings, #f otherwise
  4438.  
  4439.        8.  hours west of GMT (-24 - +24)
  4440.  
  4441.      Notice that the values returned by `decode-universal-time' do not
  4442.      match the arguments to `encode-universal-time'.
  4443.  
  4444.  - Function: encode-universal-time SECOND MINUTE HOUR DATE MONTH YEAR
  4445.  - Function: encode-universal-time SECOND MINUTE HOUR DATE MONTH YEAR
  4446.           TIME-ZONE
  4447.      Converts the arguments in Decoded Time format to Universal Time
  4448.      format.  If TIME-ZONE is not specified, the returned time is
  4449.      adjusted for daylight saving time.  Otherwise, no adjustment is
  4450.      performed.
  4451.  
  4452.      Notice that the values returned by `decode-universal-time' do not
  4453.      match the arguments to `encode-universal-time'.
  4454.  
  4455. 
  4456. File: slib.info,  Node: Vector Graphics,  Next: Schmooz,  Prev: Time and Date,  Up: Textual Conversion Packages
  4457.  
  4458. Vector Graphics
  4459. ===============
  4460.  
  4461. * Menu:
  4462.  
  4463. * Tektronix Graphics Support::
  4464.  
  4465. 
  4466. File: slib.info,  Node: Tektronix Graphics Support,  Prev: Vector Graphics,  Up: Vector Graphics
  4467.  
  4468. Tektronix Graphics Support
  4469. --------------------------
  4470.  
  4471.   *Note:* The Tektronix graphics support files need more work, and are
  4472. not complete.
  4473.  
  4474. Tektronix 4000 Series Graphics
  4475. ..............................
  4476.  
  4477.   The Tektronix 4000 series graphics protocol gives the user a 1024 by
  4478. 1024 square drawing area.  The origin is in the lower left corner of the
  4479. screen.  Increasing y is up and increasing x is to the right.
  4480.  
  4481.   The graphics control codes are sent over the current-output-port and
  4482. can be mixed with regular text and ANSI or other terminal control
  4483. sequences.
  4484.  
  4485.  - Procedure: tek40:init
  4486.  
  4487.  - Procedure: tek40:graphics
  4488.  
  4489.  - Procedure: tek40:text
  4490.  
  4491.  - Procedure: tek40:linetype LINETYPE
  4492.  
  4493.  - Procedure: tek40:move X Y
  4494.  
  4495.  - Procedure: tek40:draw X Y
  4496.  
  4497.  - Procedure: tek40:put-text X Y STR
  4498.  
  4499.  - Procedure: tek40:reset
  4500.  
  4501. Tektronix 4100 Series Graphics
  4502. ..............................
  4503.  
  4504.   The graphics control codes are sent over the current-output-port and
  4505. can be mixed with regular text and ANSI or other terminal control
  4506. sequences.
  4507.  
  4508.  - Procedure: tek41:init
  4509.  
  4510.  - Procedure: tek41:reset
  4511.  
  4512.  - Procedure: tek41:graphics
  4513.  
  4514.  - Procedure: tek41:move X Y
  4515.  
  4516.  - Procedure: tek41:draw X Y
  4517.  
  4518.  - Procedure: tek41:point X Y NUMBER
  4519.  
  4520.  - Procedure: tek41:encode-x-y X Y
  4521.  
  4522.  - Procedure: tek41:encode-int NUMBER
  4523.  
  4524. 
  4525. File: slib.info,  Node: Schmooz,  Prev: Vector Graphics,  Up: Textual Conversion Packages
  4526.  
  4527. Schmooz
  4528. =======
  4529.  
  4530.   "Schmooz" is a simple, lightweight markup language for interspersing
  4531. Texinfo documentation with Scheme source code.  Schmooz does not create
  4532. the top level Texinfo file; it creates `txi' files which can be
  4533. imported into the documentation using the Texinfo command `@include'.
  4534.  
  4535.   `(require 'schmooz)' defines the function `schmooz', which is used to
  4536. process files.  Files containing schmooz documentation should not
  4537. contain `(require 'schmooz)'.
  4538.  
  4539.  - Procedure: schmooz FILENAMEscm ...
  4540.      FILENAMEscm should be a string ending with `scm' naming an
  4541.      existing file containing Scheme source code.  `schmooz' extracts
  4542.      top-level comments containing schmooz commands from FILENAMEscm
  4543.      and writes the converted Texinfo source to a file named
  4544.      FILENAMEtxi.
  4545.  
  4546.  - Procedure: schmooz FILENAMEtexi ...
  4547.  - Procedure: schmooz FILENAMEtex ...
  4548.  - Procedure: schmooz FILENAMEtxi ...
  4549.      FILENAME should be a string naming an existing file containing
  4550.      Texinfo source code.  For every occurrence of the string `@include
  4551.      FILENAMEtxi' within that file, `schmooz' calls itself with the
  4552.      argument `FILENAMEscm'.
  4553.  
  4554.   Schmooz comments are distinguished (from non-schmooz comments) by
  4555. their first line, which must start with an at-sign (@) preceded by one
  4556. or more semicolons (;).  A schmooz comment ends at the first subsequent
  4557. line which does *not* start with a semicolon.  Currently schmooz
  4558. comments are recognized only at top level.
  4559.  
  4560.   Schmooz comments are copied to the Texinfo output file with the
  4561. leading contiguous semicolons removed.  Certain character sequences
  4562. starting with at-sign are treated specially.  Others are copied
  4563. unchanged.
  4564.  
  4565.   A schmooz comment starting with `@body' must be followed by a Scheme
  4566. definition.  All comments between the `@body' line and the definition
  4567. will be included in a Texinfo definition, either a `@defun' or a
  4568. `@defvar', depending on whether a procedure or a variable is being
  4569. defined.
  4570.  
  4571.   Within the text of that schmooz comment, at-sign followed by `0' will
  4572. be replaced by `@code{procedure-name}' if the following definition is
  4573. of a procedure; or `@var{variable}' if defining a variable.
  4574.  
  4575.   An at-sign followed by a non-zero digit will expand to the variable
  4576. citation of that numbered argument: `@var{argument-name}'.
  4577.  
  4578.   If more than one definition follows a `@body' comment line without an
  4579. intervening blank or comment line, then those definitions will be
  4580. included in the same Texinfo definition using `@defvarx' or `@defunx',
  4581. depending on whether the first definition is of a variable or of a
  4582. procedure.
  4583.  
  4584.   Schmooz can figure out whether a definition is of a procedure if it
  4585. is of the form:
  4586.  
  4587.   `(define (<identifier> <arg> ...) <expression>)'
  4588.  
  4589. or if the left hand side of the definition is some form ending in a
  4590. lambda expression.  Obviously, it can be fooled.  In order to force
  4591. recognition of a procedure definition, start the documentation with
  4592. `@args' instead of `@body'.  `@args' should be followed by the argument
  4593. list of the function being defined, which may be enclosed in
  4594. parentheses and delimited by whitespace, (as in Scheme), enclosed in
  4595. braces and separated by commas, (as in Texinfo), or consist of the
  4596. remainder of the line, separated by whitespace.
  4597.  
  4598.   For example:
  4599.  
  4600.      ;;@args arg1 args ...
  4601.      ;;@0 takes argument @1 and any number of @2
  4602.      (define myfun (some-function-returning-magic))
  4603.  
  4604.   Will result in:
  4605.  
  4606.      @defun myfun arg1 args @dots{}
  4607.      
  4608.      @code{myfun} takes argument @var{arg1} and any number of @var{args}
  4609.      @end defun
  4610.  
  4611.   `@args' may also be useful for indicating optional arguments by name.
  4612. If `@args' occurs inside a schmooz comment section, rather than at the
  4613. beginning, then it will generate a `@defunx' line with the arguments
  4614. supplied.
  4615.  
  4616.   If the first at-sign in a schmooz comment is immediately followed by
  4617. whitespace, then the comment will be expanded to whatever follows that
  4618. whitespace.  If the at-sign is followed by a non-whitespace character
  4619. then the at-sign will be included as the first character of the
  4620. expansion.  This feature is intended to make it easy to include Texinfo
  4621. directives in schmooz comments.
  4622.  
  4623. 
  4624. File: slib.info,  Node: Mathematical Packages,  Next: Database Packages,  Prev: Textual Conversion Packages,  Up: Top
  4625.  
  4626. Mathematical Packages
  4627. *********************
  4628.  
  4629. * Menu:
  4630.  
  4631. * Bit-Twiddling::               'logical
  4632. * Modular Arithmetic::          'modular
  4633. * Prime Numbers::               'factor
  4634. * Random Numbers::              'random
  4635. * Fast Fourier Transform::      'fft
  4636. * Cyclic Checksum::             'make-crc
  4637. * Plotting::                    'charplot
  4638. * Root Finding::                'root
  4639. * Minimizing::                  'minimize                                     |
  4640. * Commutative Rings::           'commutative-ring
  4641. * Determinant::                 'determinant
  4642.  
  4643. 
  4644. File: slib.info,  Node: Bit-Twiddling,  Next: Modular Arithmetic,  Prev: Mathematical Packages,  Up: Mathematical Packages
  4645.  
  4646. Bit-Twiddling
  4647. =============
  4648.  
  4649.   `(require 'logical)'
  4650.  
  4651.   The bit-twiddling functions are made available through the use of the
  4652. `logical' package.  `logical' is loaded by inserting `(require
  4653. 'logical)' before the code that uses these functions.  These functions
  4654. behave as though operating on integers in two's-complement
  4655. representation.
  4656.  
  4657. Bitwise Operations
  4658. ------------------
  4659.  
  4660.  - Function: logand N1 N1
  4661.      Returns the integer which is the bit-wise AND of the two integer
  4662.      arguments.
  4663.  
  4664.      Example:
  4665.           (number->string (logand #b1100 #b1010) 2)
  4666.              => "1000"
  4667.  
  4668.  - Function: logior N1 N2
  4669.      Returns the integer which is the bit-wise OR of the two integer
  4670.      arguments.
  4671.  
  4672.      Example:
  4673.           (number->string (logior #b1100 #b1010) 2)
  4674.              => "1110"
  4675.  
  4676.  - Function: logxor N1 N2
  4677.      Returns the integer which is the bit-wise XOR of the two integer
  4678.      arguments.
  4679.  
  4680.      Example:
  4681.           (number->string (logxor #b1100 #b1010) 2)
  4682.              => "110"
  4683.  
  4684.  - Function: lognot N
  4685.      Returns the integer which is the 2s-complement of the integer
  4686.      argument.
  4687.  
  4688.      Example:
  4689.           (number->string (lognot #b10000000) 2)
  4690.              => "-10000001"
  4691.           (number->string (lognot #b0) 2)
  4692.              => "-1"
  4693.  
  4694.  - Function: bitwise-if MASK N0 N1
  4695.      Returns an integer composed of some bits from integer N0 and some
  4696.      from integer N1.  A bit of the result is taken from N0 if the
  4697.      corresponding bit of integer MASK is 1 and from N1 if that bit of
  4698.      MASK is 0.
  4699.  
  4700.  - Function: logtest J K
  4701.           (logtest j k) == (not (zero? (logand j k)))
  4702.           
  4703.           (logtest #b0100 #b1011) => #f
  4704.           (logtest #b0100 #b0111) => #t
  4705.  
  4706.  - Function: logcount N
  4707.      Returns the number of bits in integer N.  If integer is positive,
  4708.      the 1-bits in its binary representation are counted.  If negative,
  4709.      the 0-bits in its two's-complement binary representation are
  4710.      counted.  If 0, 0 is returned.
  4711.  
  4712.      Example:
  4713.           (logcount #b10101010)
  4714.              => 4
  4715.           (logcount 0)
  4716.              => 0
  4717.           (logcount -2)
  4718.              => 1
  4719.  
  4720. Bit Within Word
  4721. ---------------
  4722.  
  4723.  - Function: logbit? INDEX J
  4724.           (logbit? index j) == (logtest (integer-expt 2 index) j)
  4725.           
  4726.           (logbit? 0 #b1101) => #t
  4727.           (logbit? 1 #b1101) => #f
  4728.           (logbit? 2 #b1101) => #t
  4729.           (logbit? 3 #b1101) => #t
  4730.           (logbit? 4 #b1101) => #f
  4731.  
  4732.  - Function: copy-bit INDEX FROM BIT
  4733.      Returns an integer the same as FROM except in the INDEXth bit,
  4734.      which is 1 if BIT is `#t' and 0 if BIT is `#f'.
  4735.  
  4736.      Example:
  4737.           (number->string (copy-bit 0 0 #t) 2)       => "1"
  4738.           (number->string (copy-bit 2 0 #t) 2)       => "100"
  4739.           (number->string (copy-bit 2 #b1111 #f) 2)  => "1011"
  4740.  
  4741. Fields of Bits
  4742. --------------
  4743.  
  4744.  - Function: bit-field N START END
  4745.      Returns the integer composed of the START (inclusive) through END
  4746.      (exclusive) bits of N.  The STARTth bit becomes the 0-th bit in
  4747.      the result.
  4748.  
  4749.      This function was called `bit-extract' in previous versions of
  4750.      SLIB.
  4751.  
  4752.      Example:
  4753.           (number->string (bit-field #b1101101010 0 4) 2)
  4754.              => "1010"
  4755.           (number->string (bit-field #b1101101010 4 9) 2)
  4756.              => "10110"
  4757.  
  4758.  - Function: copy-bit-field TO START END FROM
  4759.      Returns an integer the same as TO except possibly in the START
  4760.      (inclusive) through END (exclusive) bits, which are the same as
  4761.      those of FROM.  The 0-th bit of FROM becomes the STARTth bit of
  4762.      the result.
  4763.  
  4764.      Example:
  4765.           (number->string (copy-bit-field #b1101101010 0 4 0) 2)
  4766.                   => "1101100000"
  4767.           (number->string (copy-bit-field #b1101101010 0 4 -1) 2)
  4768.                   => "1101101111"
  4769.  
  4770.  - Function: ash INT COUNT
  4771.      Returns an integer equivalent to `(inexact->exact (floor (* INT
  4772.      (expt 2 COUNT))))'.
  4773.  
  4774.      Example:
  4775.           (number->string (ash #b1 3) 2)
  4776.              => "1000"
  4777.           (number->string (ash #b1010 -1) 2)
  4778.              => "101"
  4779.  
  4780.  - Function: integer-length N
  4781.      Returns the number of bits neccessary to represent N.
  4782.  
  4783.      Example:
  4784.           (integer-length #b10101010)
  4785.              => 8
  4786.           (integer-length 0)
  4787.              => 0
  4788.           (integer-length #b1111)
  4789.              => 4
  4790.  
  4791.  - Function: integer-expt N K
  4792.      Returns N raised to the non-negative integer exponent K.
  4793.  
  4794.      Example:
  4795.           (integer-expt 2 5)
  4796.              => 32
  4797.           (integer-expt -3 3)
  4798.              => -27
  4799.  
  4800. 
  4801. File: slib.info,  Node: Modular Arithmetic,  Next: Prime Numbers,  Prev: Bit-Twiddling,  Up: Mathematical Packages
  4802.  
  4803. Modular Arithmetic
  4804. ==================
  4805.  
  4806.   `(require 'modular)'
  4807.  
  4808.  - Function: extended-euclid N1 N2
  4809.      Returns a list of 3 integers `(d x y)' such that d = gcd(N1, N2) =
  4810.      N1 * x + N2 * y.
  4811.  
  4812.  - Function: symmetric:modulus N
  4813.      Returns `(quotient (+ -1 n) -2)' for positive odd integer N.
  4814.  
  4815.  - Function: modulus->integer MODULUS
  4816.      Returns the non-negative integer characteristic of the ring formed
  4817.      when MODULUS is used with `modular:' procedures.
  4818.  
  4819.  - Function: modular:normalize MODULUS N
  4820.      Returns the integer `(modulo N (modulus->integer MODULUS))' in the
  4821.      representation specified by MODULUS.
  4822.  
  4823. The rest of these functions assume normalized arguments; That is, the
  4824. arguments are constrained by the following table:
  4825.  
  4826. For all of these functions, if the first argument (MODULUS) is:
  4827. `positive?'
  4828.      Work as before.  The result is between 0 and MODULUS.
  4829.  
  4830. `zero?'
  4831.      The arguments are treated as integers.  An integer is returned.
  4832.  
  4833. `negative?'
  4834.      The arguments and result are treated as members of the integers
  4835.      modulo `(+ 1 (* -2 MODULUS))', but with "symmetric"
  4836.      representation; i.e. `(<= (- MODULUS) N MODULUS)'.
  4837.  
  4838. If all the arguments are fixnums the computation will use only fixnums.
  4839.  
  4840.  - Function: modular:invertable? MODULUS K
  4841.      Returns `#t' if there exists an integer n such that K * n == 1 mod
  4842.      MODULUS, and `#f' otherwise.
  4843.  
  4844.  - Function: modular:invert MODULUS K2
  4845.      Returns an integer n such that 1 = (n * K2) mod MODULUS.  If K2
  4846.      has no inverse mod MODULUS an error is signaled.
  4847.  
  4848.  - Function: modular:negate MODULUS K2
  4849.      Returns (-K2) mod MODULUS.
  4850.  
  4851.  - Function: modular:+ MODULUS K2 K3
  4852.      Returns (K2 + K3) mod MODULUS.
  4853.  
  4854.  - Function: modular:- MODULUS K2 K3
  4855.      Returns (K2 - K3) mod MODULUS.
  4856.  
  4857.  - Function: modular:* MODULUS K2 K3
  4858.      Returns (K2 * K3) mod MODULUS.
  4859.  
  4860.      The Scheme code for `modular:*' with negative MODULUS is not
  4861.      completed for fixnum-only implementations.
  4862.  
  4863.  - Function: modular:expt MODULUS K2 K3
  4864.      Returns (K2 ^ K3) mod MODULUS.
  4865.  
  4866. 
  4867. File: slib.info,  Node: Prime Numbers,  Next: Random Numbers,  Prev: Modular Arithmetic,  Up: Mathematical Packages
  4868.  
  4869. Prime Numbers
  4870. =============
  4871.  
  4872.   `(require 'factor)'
  4873.  
  4874.  - Variable: prime:prngs
  4875.      PRIME:PRNGS is the random-state (*note Random Numbers::.) used by
  4876.      these procedures.  If you call these procedures from more than one
  4877.      thread (or from interrupt), `random' may complain about reentrant
  4878.      calls.
  4879.   *Note:* The prime test and generation procedures implement (or use)
  4880. the Solovay-Strassen primality test. See
  4881.  
  4882.    * Robert Solovay and Volker Strassen, `A Fast Monte-Carlo Test for
  4883.      Primality', SIAM Journal on Computing, 1977, pp 84-85.
  4884.  
  4885.  - Function: jacobi-symbol P Q
  4886.      Returns the value (+1, -1, or 0) of the Jacobi-Symbol of exact
  4887.      non-negative integer P and exact positive odd integer Q.
  4888.  
  4889.  - Variable: prime:trials
  4890.      PRIME:TRIALS the maxinum number of iterations of Solovay-Strassen
  4891.      that will be done to test a number for primality.
  4892.  
  4893.  - Function: prime? N
  4894.      Returns `#f' if N is composite; `#t' if N is prime.  There is a
  4895.      slight chance `(expt 2 (- prime:trials))' that a composite will
  4896.      return `#t'.
  4897.  
  4898.  - Function: primes< START COUNT
  4899.      Returns a list of the first COUNT prime numbers less than START.
  4900.      If there are fewer than COUNT prime numbers less than START, then
  4901.      the returned list will have fewer than START elements.
  4902.  
  4903.  - Function: primes> START COUNT
  4904.      Returns a list of the first COUNT prime numbers greater than START.
  4905.  
  4906.  - Function: factor K
  4907.      Returns a list of the prime factors of K.  The order of the
  4908.      factors is unspecified.  In order to obtain a sorted list do
  4909.      `(sort! (factor K) <)'.
  4910.  
  4911. 
  4912. File: slib.info,  Node: Random Numbers,  Next: Fast Fourier Transform,  Prev: Prime Numbers,  Up: Mathematical Packages
  4913.  
  4914. Random Numbers
  4915. ==============
  4916.  
  4917.   `(require 'random)'
  4918.  
  4919.   A pseudo-random number generator is only as good as the tests it
  4920. passes.  George Marsaglia of Florida State University developed a
  4921. battery of tests named "DIEHARD"
  4922. (`http://stat.fsu.edu/~geo/diehard.html').  `diehard.c' has a bug which
  4923. the patch
  4924. `http://swissnet.ai.mit.edu/ftpdir/users/jaffer/diehard.c.pat' corrects.
  4925.  
  4926.   SLIB's new PRNG generates 8 bits at a time.  With the degenerate seed
  4927. `0', the numbers generated pass DIEHARD; but when bits are combined
  4928. from sequential bytes, tests fail.  With the seed
  4929. `http://swissnet.ai.mit.edu/~jaffer/SLIB.html', all of those tests pass.
  4930.  
  4931.  - Function: random N
  4932.  - Function: random N STATE
  4933.      Accepts a positive integer or real N and returns a number of the
  4934.      same type between zero (inclusive) and N (exclusive).  The values
  4935.      returned by `random' are uniformly distributed from 0 to N.
  4936.  
  4937.      The optional argument STATE must be of the type returned by
  4938.      `(seed->random-state)' or `(make-random-state)'.  It defaults to
  4939.      the value of the variable `*random-state*'.  This object is used
  4940.      to maintain the state of the pseudo-random-number generator and is
  4941.      altered as a side effect of calls to `random'.
  4942.  
  4943.  - Variable: *random-state*
  4944.      Holds a data structure that encodes the internal state of the
  4945.      random-number generator that `random' uses by default.  The nature
  4946.      of this data structure is implementation-dependent.  It may be
  4947.      printed out and successfully read back in, but may or may not
  4948.      function correctly as a random-number state object in another
  4949.      implementation.
  4950.  
  4951.  - Function: copy-random-state STATE
  4952.      Returns a new copy of argument STATE.
  4953.  
  4954.  - Function: copy-random-state
  4955.      Returns a new copy of `*random-state*'.
  4956.  
  4957.  - Function: seed->random-state SEED
  4958.      Returns a new object of type suitable for use as the value of the
  4959.      variable `*random-state*' or as a second argument to `random'.
  4960.      The number or string SEED is used to initialize the state.  If
  4961.      `seed->random-state' is called twice with arguments which are
  4962.      `equal?', then the returned data structures will be `equal?'.
  4963.      Calling `seed->random-state' with unequal arguments will nearly
  4964.      always return unequal states.
  4965.  
  4966.  - Function: make-random-state
  4967.  - Function: make-random-state OBJ
  4968.      Returns a new object of type suitable for use as the value of the
  4969.      variable `*random-state*' or as a second argument to `random'.  If
  4970.      the optional argument OBJ is given, it should be a printable
  4971.      Scheme object; the first 50 characters of its printed
  4972.      representation will be used as the seed.  Otherwise the value of
  4973.      `*random-state*' is used as the seed.
  4974.  
  4975.   If inexact numbers are supported by the Scheme implementation,
  4976. `randinex.scm' will be loaded as well.  `randinex.scm' contains
  4977. procedures for generating inexact distributions.
  4978.  
  4979.  - Function: random:uniform
  4980.  - Function: random:uniform STATE
  4981.      Returns an uniformly distributed inexact real random number in the
  4982.      range between 0 and 1.
  4983.  
  4984.  - Function: random:exp
  4985.  - Function: random:exp STATE
  4986.      Returns an inexact real in an exponential distribution with mean
  4987.      1.  For an exponential distribution with mean U use
  4988.      `(* U (random:exp))'.
  4989.  
  4990.  - Function: random:normal
  4991.  - Function: random:normal STATE
  4992.      Returns an inexact real in a normal distribution with mean 0 and
  4993.      standard deviation 1.  For a normal distribution with mean M and
  4994.      standard deviation D use `(+ M (* D (random:normal)))'.
  4995.  
  4996.  - Function: random:normal-vector! VECT
  4997.  - Function: random:normal-vector! VECT STATE
  4998.      Fills VECT with inexact real random numbers which are independent
  4999.      and standard normally distributed (i.e., with mean 0 and variance
  5000.      1).
  5001.  
  5002.  - Function: random:hollow-sphere! VECT
  5003.  - Function: random:hollow-sphere! VECT STATE
  5004.      Fills VECT with inexact real random numbers the sum of whose
  5005.      squares is less than 1.0.  Thinking of VECT as coordinates in
  5006.      space of dimension N = `(vector-length VECT)', the coordinates are
  5007.      uniformly distributed within the unit N-shere.  The sum of the
  5008.      squares of the numbers is returned.
  5009.  
  5010.  - Function: random:solid-sphere! VECT
  5011.  - Function: random:solid-sphere! VECT STATE
  5012.      Fills VECT with inexact real random numbers the sum of whose
  5013.      squares is equal to 1.0.  Thinking of VECT as coordinates in space
  5014.      of dimension n = `(vector-length VECT)', the coordinates are
  5015.      uniformly distributed over the surface of the unit n-shere.
  5016.  
  5017. 
  5018. File: slib.info,  Node: Fast Fourier Transform,  Next: Cyclic Checksum,  Prev: Random Numbers,  Up: Mathematical Packages
  5019.  
  5020. Fast Fourier Transform
  5021. ======================
  5022.  
  5023.   `(require 'fft)'
  5024.  
  5025.  - Function: fft ARRAY
  5026.      ARRAY is an array of `(expt 2 n)' numbers.  `fft' returns an array
  5027.      of complex numbers comprising the "Discrete Fourier Transform" of
  5028.      ARRAY.
  5029.  
  5030.  - Function: fft-1 ARRAY
  5031.      `fft-1' returns an array of complex numbers comprising the inverse
  5032.      Discrete Fourier Transform of ARRAY.
  5033.  
  5034.   `(fft-1 (fft ARRAY))' will return an array of values close to ARRAY.
  5035.  
  5036.      (fft '#(1 0+i -1 0-i 1 0+i -1 0-i)) =>
  5037.      
  5038.      #(0.0 0.0 0.0+628.0783185208527e-18i 0.0
  5039.        0.0 0.0 8.0-628.0783185208527e-18i 0.0)
  5040.      
  5041.      (fft-1 '#(0 0 0 0 0 0 8 0)) =>
  5042.      
  5043.      #(1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i
  5044.        1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i)
  5045.  
  5046. 
  5047. File: slib.info,  Node: Cyclic Checksum,  Next: Plotting,  Prev: Fast Fourier Transform,  Up: Mathematical Packages
  5048.  
  5049. Cyclic Checksum
  5050. ===============
  5051.  
  5052.   `(require 'make-crc)'
  5053.  
  5054.  - Function: make-port-crc
  5055.  - Function: make-port-crc DEGREE
  5056.  - Function: make-port-crc DEGREE GENERATOR
  5057.      Returns an expression for a procedure of one argument, a port.
  5058.      This procedure reads characters from the port until the end of
  5059.      file and returns the integer checksum of the bytes read.
  5060.  
  5061.      The integer DEGREE, if given, specifies the degree of the
  5062.      polynomial being computed - which is also the number of bits
  5063.      computed in the checksums.  The default value is 32.
  5064.  
  5065.      The integer GENERATOR specifies the polynomial being computed.
  5066.      The power of 2 generating each 1 bit is the exponent of a term of
  5067.      the polynomial.  The bit at position DEGREE is implicit and should
  5068.      not be part of GENERATOR.  This allows systems with numbers
  5069.      limited to 32 bits to calculate 32 bit checksums.  The default
  5070.      value of GENERATOR when DEGREE is 32 (its default) is:
  5071.  
  5072.           (make-port-crc 32 #b00000100110000010001110110110111)
  5073.  
  5074.      Creates a procedure to calculate the P1003.2/D11.2 (POSIX.2) 32-bit
  5075.      checksum from the polynomial:
  5076.  
  5077.                32    26    23    22    16    12    11
  5078.             ( x   + x   + x   + x   + x   + x   + x   +
  5079.           
  5080.                 10    8    7    5    4    2    1
  5081.                x   + x  + x  + x  + x  + x  + x  + 1 )  mod 2
  5082.  
  5083.      (require 'make-crc)
  5084.      (define crc32 (slib:eval (make-port-crc)))
  5085.      (define (file-check-sum file) (call-with-input-file file crc32))
  5086.      (file-check-sum (in-vicinity (library-vicinity) "ratize.scm"))
  5087.      
  5088.      => 3553047446
  5089.  
  5090. 
  5091. File: slib.info,  Node: Plotting,  Next: Root Finding,  Prev: Cyclic Checksum,  Up: Mathematical Packages
  5092.  
  5093. Plotting on Character Devices
  5094. =============================
  5095.  
  5096.   `(require 'charplot)'
  5097.  
  5098.   The plotting procedure is made available through the use of the
  5099. `charplot' package.  `charplot' is loaded by inserting `(require
  5100. 'charplot)' before the code that uses this procedure.
  5101.  
  5102.  - Variable: charplot:height
  5103.      The number of rows to make the plot vertically.
  5104.  
  5105.  - Variable: charplot:width
  5106.      The number of columns to make the plot horizontally.
  5107.  
  5108.  - Procedure: plot! COORDS X-LABEL Y-LABEL
  5109.      COORDS is a list of pairs of x and y coordinates.  X-LABEL and
  5110.      Y-LABEL are strings with which to label the x and y axes.
  5111.  
  5112.      Example:
  5113.           (require 'charplot)
  5114.           (set! charplot:height 19)
  5115.           (set! charplot:width 45)
  5116.           
  5117.           (define (make-points n)
  5118.             (if (zero? n)
  5119.                 '()
  5120.                 (cons (cons (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
  5121.           
  5122.           (plot! (make-points 37) "x" "Sin(x)")
  5123.           -|
  5124.             Sin(x)   ______________________________________________
  5125.                 1.25|-                                             |
  5126.                     |                                              |
  5127.                    1|-       ****                                  |
  5128.                     |      **    **                                |
  5129.             750.0e-3|-    *        *                               |
  5130.                     |    *          *                              |
  5131.             500.0e-3|-  *            *                             |
  5132.                     |  *                                           |
  5133.             250.0e-3|-                *                            |
  5134.                     | *                *                           |
  5135.                    0|-------------------*--------------------------|
  5136.                     |                                     *        |
  5137.            -250.0e-3|-                   *               *         |
  5138.                     |                     *             *          |
  5139.            -500.0e-3|-                     *                       |
  5140.                     |                       *          *           |
  5141.            -750.0e-3|-                       *        *            |
  5142.                     |                         **    **             |
  5143.                   -1|-                          ****               |
  5144.                     |____________:_____._____:_____._____:_________|
  5145.                   x              2           4
  5146.  
  5147. 
  5148. File: slib.info,  Node: Root Finding,  Next: Minimizing,  Prev: Plotting,  Up: Mathematical Packages
  5149.                                                                               |
  5150. Root Finding
  5151. ============
  5152.  
  5153.   `(require 'root)'
  5154.  
  5155.  - Function: newtown:find-integer-root F DF/DX X0
  5156.      Given integer valued procedure F, its derivative (with respect to
  5157.      its argument) DF/DX, and initial integer value X0 for which
  5158.      DF/DX(X0) is non-zero, returns an integer X for which F(X) is
  5159.      closer to zero than either of the integers adjacent to X; or
  5160.      returns `#f' if such an integer can't be found.
  5161.  
  5162.      To find the closest integer to a given integers square root:
  5163.  
  5164.           (define (integer-sqrt y)
  5165.             (newton:find-integer-root
  5166.              (lambda (x) (- (* x x) y))
  5167.              (lambda (x) (* 2 x))
  5168.              (ash 1 (quotient (integer-length y) 2))))
  5169.           
  5170.           (integer-sqrt 15) => 4
  5171.  
  5172.  - Function: integer-sqrt Y
  5173.      Given a non-negative integer Y, returns the rounded square-root of
  5174.      Y.
  5175.  
  5176.  - Function: newton:find-root F DF/DX X0 PREC
  5177.      Given real valued procedures F, DF/DX of one (real) argument,
  5178.      initial real value X0 for which DF/DX(X0) is non-zero, and
  5179.      positive real number PREC, returns a real X for which `abs'(F(X))
  5180.      is less than PREC; or returns `#f' if such a real can't be found.
  5181.  
  5182.      If PREC is instead a negative integer, `newton:find-root' returns
  5183.      the result of -PREC iterations.
  5184.  
  5185. H. J. Orchard, `The Laguerre Method for Finding the Zeros of
  5186. Polynomials', IEEE Transactions on Circuits and Systems, Vol. 36, No.
  5187. 11, November 1989, pp 1377-1381.
  5188.  
  5189.      There are 2 errors in Orchard's Table II.  Line k=2 for starting
  5190.      value of 1000+j0 should have Z_k of 1.0475 + j4.1036 and line k=2
  5191.      for starting value of 0+j1000 should have Z_k of 1.0988 + j4.0833.
  5192.  
  5193.  - Function: laguerre:find-root F DF/DZ DDF/DZ^2 Z0 PREC
  5194.      Given complex valued procedure F of one (complex) argument, its
  5195.      derivative (with respect to its argument) DF/DX, its second
  5196.      derivative DDF/DZ^2, initial complex value Z0, and positive real
  5197.      number PREC, returns a complex number Z for which
  5198.      `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
  5199.      number can't be found.
  5200.  
  5201.      If PREC is instead a negative integer, `laguerre:find-root'
  5202.      returns the result of -PREC iterations.
  5203.  
  5204.  - Function: laguerre:find-polynomial-root DEG F DF/DZ DDF/DZ^2 Z0 PREC
  5205.      Given polynomial procedure F of integer degree DEG of one
  5206.      argument, its derivative (with respect to its argument) DF/DX, its
  5207.      second derivative DDF/DZ^2, initial complex value Z0, and positive
  5208.      real number PREC, returns a complex number Z for which
  5209.      `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
  5210.      number can't be found.
  5211.  
  5212.      If PREC is instead a negative integer,
  5213.      `laguerre:find-polynomial-root' returns the result of -PREC
  5214.      iterations.
  5215.  
  5216.  - Function: secant:find-root F X0 X1 PREC
  5217.  - Function: secant:find-bracketed-root F X0 X1 PREC
  5218.      Given a real valued procedure F and two real valued starting
  5219.      points X0 and X1, returns a real X for which `(abs (f x))' is less
  5220.      than PREC; or returns `#f' if such a real can't be found.
  5221.  
  5222.      If X0 and X1 are chosen such that they bracket a root, that is
  5223.           (or (< (f x0) 0 (f x1))
  5224.               (< (f x1) 0 (f x0)))
  5225.      then the root returned will be between X0 and X1, and F will not
  5226.      be passed an argument outside of that interval.
  5227.  
  5228.      `secant:find-bracketed-root' will return `#f' unless X0 and X1
  5229.      bracket a root.
  5230.  
  5231.      The secant method is used until a bracketing interval is found, at
  5232.      which point a modified regula falsi method is used.
  5233.  
  5234.      If PREC is instead a negative integer, `secant:find-root' returns
  5235.      the result of -PREC iterations.
  5236.  
  5237.      If PREC is a procedure it should accept 5 arguments: X0 F0 X1 F1
  5238.      and COUNT, where F0 will be `(f x0)', F1 `(f x1)', and COUNT the
  5239.      number of iterations performed so far.  PREC should return
  5240.      non-false if the iteration should be stopped.
  5241.  
  5242. 
  5243. File: slib.info,  Node: Minimizing,  Next: Commutative Rings,  Prev: Root Finding,  Up: Mathematical Packages
  5244.                                                                               |
  5245. Minimizing                                                                    |
  5246. ==========                                                                    |
  5247.                                                                               |
  5248.   `(require 'minimize)'                                                       |
  5249.                                                                               |
  5250. The Golden Section Search (1) algorithm finds minima of functions which       |
  5251. are expensive to compute or for which derivatives are not available.          |
  5252. Although optimum for the general case, convergence is slow, requiring         |
  5253. nearly 100 iterations for the example (x^3-2x-5).                             |
  5254.                                                                               |
  5255. If the derivative is available, Newton-Raphson is probably a better           |
  5256. choice.  If the function is inexpensive to compute, consider                  |
  5257. approximating the derivative.                                                 |
  5258.                                                                               |
  5259.  - Function: golden-section-search F X0 X1 PREC                               |
  5260.      X_0 are X_1 real numbers.  The (single argument) procedure F is          |
  5261.      unimodal over the open interval (X_0, X_1).  That is, there is           |
  5262.      exactly one point in the interval for which the derivative of F is       |
  5263.      zero.                                                                    |
  5264.                                                                               |
  5265.      `golden-section-search' returns a pair (X . F(X)) where F(X) is          |
  5266.      the minimum.  The PREC parameter is the stop criterion.  If PREC         |
  5267.      is a positive number, then the iteration continues until X is            |
  5268.      within PREC from the true value.  If PREC is a negative integer,         |
  5269.      then the procedure will iterate -PREC times or until convergence.        |
  5270.      If PREC is a procedure of seven arguments, X0, X1, A, B, FA, FB,         |
  5271.      and COUNT, then the iterations will stop when the procedure              |
  5272.      returns `#t'.                                                            |
  5273.                                                                               |
  5274.      Analytically, the minimum of x^3-2x-5 is 0.816497.                       |
  5275.           (define func (lambda (x) (+ (* x (+ (* x x) -2)) -5)))              |
  5276.           (golden-section-search func 0 1 (/ 10000))                          |
  5277.                 ==> (816.4883855245578e-3 . -6.0886621077391165)              |
  5278.           (golden-section-search func 0 1 -5)                                 |
  5279.                 ==> (819.6601125010515e-3 . -6.088637561916407)               |
  5280.           (golden-section-search func 0 1                                     |
  5281.                                  (lambda (a b c d e f g ) (= g 500)))         |
  5282.                 ==> (816.4965933140557e-3 . -6.088662107903635)               |
  5283.                                                                               |
  5284.   ---------- Footnotes ----------                                             |
  5285.                                                                               |
  5286.   (1) David Kahaner, Cleve Moler, and Stephen Nash `Numerical Methods         |
  5287. and Software' Prentice-Hall, 1989, ISBN 0-13-627258-4                         |
  5288.                                                                               |
  5289. 
  5290. File: slib.info,  Node: Commutative Rings,  Next: Determinant,  Prev: Minimizing,  Up: Mathematical Packages
  5291.                                                                               |
  5292. Commutative Rings
  5293. =================
  5294.  
  5295.   Scheme provides a consistent and capable set of numeric functions.
  5296. Inexacts implement a field; integers a commutative ring (and Euclidean
  5297. domain).  This package allows one to use basic Scheme numeric functions
  5298. with symbols and non-numeric elements of commutative rings.
  5299.  
  5300.   `(require 'commutative-ring)'
  5301.  
  5302.   The "commutative-ring" package makes the procedures `+', `-', `*',
  5303. `/', and `^' "careful" in the sense that any non-numeric arguments they
  5304. do not reduce appear in the expression output.  In order to see what
  5305. working with this package is like, self-set all the single letter
  5306. identifiers (to their corresponding symbols).
  5307.  
  5308.      (define a 'a)
  5309.      ...
  5310.      (define z 'z)
  5311.  
  5312.   Or just `(require 'self-set)'.  Now try some sample expressions:
  5313.  
  5314.      (+ (+ a b) (- a b)) => (* a 2)
  5315.      (* (+ a b) (+ a b)) => (^ (+ a b) 2)
  5316.      (* (+ a b) (- a b)) => (* (+ a b) (- a b))
  5317.      (* (- a b) (- a b)) => (^ (- a b) 2)
  5318.      (* (- a b) (+ a b)) => (* (+ a b) (- a b))
  5319.      (/ (+ a b) (+ c d)) => (/ (+ a b) (+ c d))
  5320.      (^ (+ a b) 3) => (^ (+ a b) 3)
  5321.      (^ (+ a 2) 3) => (^ (+ 2 a) 3)
  5322.  
  5323.   Associative rules have been applied and repeated addition and
  5324. multiplication converted to multiplication and exponentiation.
  5325.  
  5326.   We can enable distributive rules, thus expanding to sum of products
  5327. form:
  5328.      (set! *ruleset* (combined-rulesets distribute* distribute/))
  5329.      
  5330.      (* (+ a b) (+ a b)) => (+ (* 2 a b) (^ a 2) (^ b 2))
  5331.      (* (+ a b) (- a b)) => (- (^ a 2) (^ b 2))
  5332.      (* (- a b) (- a b)) => (- (+ (^ a 2) (^ b 2)) (* 2 a b))
  5333.      (* (- a b) (+ a b)) => (- (^ a 2) (^ b 2))
  5334.      (/ (+ a b) (+ c d)) => (+ (/ a (+ c d)) (/ b (+ c d)))
  5335.      (/ (+ a b) (- c d)) => (+ (/ a (- c d)) (/ b (- c d)))
  5336.      (/ (- a b) (- c d)) => (- (/ a (- c d)) (/ b (- c d)))
  5337.      (/ (- a b) (+ c d)) => (- (/ a (+ c d)) (/ b (+ c d)))
  5338.      (^ (+ a b) 3) => (+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3))
  5339.      (^ (+ a 2) 3) => (+ 8 (* a 12) (* (^ a 2) 6) (^ a 3))
  5340.  
  5341.   Use of this package is not restricted to simple arithmetic
  5342. expressions:
  5343.  
  5344.      (require 'determinant)
  5345.      
  5346.      (determinant '((a b c) (d e f) (g h i))) =>
  5347.      (- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g))
  5348.  
  5349.   Currently, only `+', `-', `*', `/', and `^' support non-numeric
  5350. elements.  Expressions with `-' are converted to equivalent expressions
  5351. without `-', so behavior for `-' is not defined separately.  `/'
  5352. expressions are handled similarly.
  5353.  
  5354.   This list might be extended to include `quotient', `modulo',
  5355. `remainder', `lcm', and `gcd'; but these work only for the more
  5356. restrictive Euclidean (Unique Factorization) Domain.
  5357.  
  5358. Rules and Rulesets
  5359. ==================
  5360.  
  5361.   The "commutative-ring" package allows control of ring properties
  5362. through the use of "rulesets".
  5363.  
  5364.  - Variable: *ruleset*
  5365.      Contains the set of rules currently in effect.  Rules defined by
  5366.      `cring:define-rule' are stored within the value of *ruleset* at the
  5367.      time `cring:define-rule' is called.  If *RULESET* is `#f', then no
  5368.      rules apply.
  5369.  
  5370.  - Function: make-ruleset RULE1 ...
  5371.  - Function: make-ruleset NAME RULE1 ...
  5372.      Returns a new ruleset containing the rules formed by applying
  5373.      `cring:define-rule' to each 4-element list argument RULE.  If the
  5374.      first argument to `make-ruleset' is a symbol, then the database
  5375.      table created for the new ruleset will be named NAME.  Calling
  5376.      `make-ruleset' with no rule arguments creates an empty ruleset.
  5377.  
  5378.  - Function: combined-rulesets RULESET1 ...
  5379.  - Function: combined-rulesets NAME RULESET1 ...
  5380.      Returns a new ruleset containing the rules contained in each
  5381.      ruleset argument RULESET.  If the first argument to
  5382.      `combined-ruleset' is a symbol, then the database table created for
  5383.      the new ruleset will be named NAME.  Calling `combined-ruleset'
  5384.      with no ruleset arguments creates an empty ruleset.
  5385.  
  5386.   Two rulesets are defined by this package.
  5387.  
  5388.  - Constant: distribute*
  5389.      Contain the ruleset to distribute multiplication over addition and
  5390.      subtraction.
  5391.  
  5392.  - Constant: distribute/
  5393.      Contain the ruleset to distribute division over addition and
  5394.      subtraction.
  5395.  
  5396.      Take care when using both DISTRIBUTE* and DISTRIBUTE/
  5397.      simultaneously.  It is possible to put `/' into an infinite loop.
  5398.  
  5399.   You can specify how sum and product expressions containing non-numeric
  5400. elements simplify by specifying the rules for `+' or `*' for cases
  5401. where expressions involving objects reduce to numbers or to expressions
  5402. involving different non-numeric elements.
  5403.  
  5404.  - Function: cring:define-rule OP SUB-OP1 SUB-OP2 REDUCTION
  5405.      Defines a rule for the case when the operation represented by
  5406.      symbol OP is applied to lists whose `car's are SUB-OP1 and
  5407.      SUB-OP2, respectively.  The argument REDUCTION is a procedure
  5408.      accepting 2 arguments which will be lists whose `car's are SUB-OP1
  5409.      and SUB-OP2.
  5410.  
  5411.  - Function: cring:define-rule OP SUB-OP1 'IDENTITY REDUCTION
  5412.      Defines a rule for the case when the operation represented by
  5413.      symbol OP is applied to a list whose `car' is SUB-OP1, and some
  5414.      other argument.  REDUCTION will be called with the list whose
  5415.      `car' is SUB-OP1 and some other argument.
  5416.  
  5417.      If REDUCTION returns `#f', the reduction has failed and other
  5418.      reductions will be tried.  If REDUCTION returns a non-false value,
  5419.      that value will replace the two arguments in arithmetic (`+', `-',
  5420.      and `*') calculations involving non-numeric elements.
  5421.  
  5422.      The operations `+' and `*' are assumed commutative; hence both
  5423.      orders of arguments to REDUCTION will be tried if necessary.
  5424.  
  5425.      The following rule is the definition for distributing `*' over `+'.
  5426.  
  5427.           (cring:define-rule
  5428.            '* '+ 'identity
  5429.            (lambda (exp1 exp2)
  5430.              (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))))
  5431.  
  5432. How to Create a Commutative Ring
  5433. ================================
  5434.  
  5435.   The first step in creating your commutative ring is to write
  5436. procedures to create elements of the ring.  A non-numeric element of
  5437. the ring must be represented as a list whose first element is a symbol
  5438. or string.  This first element identifies the type of the object.  A
  5439. convenient and clear convention is to make the type-identifying element
  5440. be the same symbol whose top-level value is the procedure to create it.
  5441.  
  5442.      (define (n . list1)
  5443.        (cond ((and (= 2 (length list1))
  5444.                    (eq? (car list1) (cadr list1)))
  5445.               0)
  5446.              ((not (term< (first list1) (last1 list1)))
  5447.               (apply n (reverse list1)))
  5448.              (else (cons 'n list1))))
  5449.      
  5450.      (define (s x y) (n x y))
  5451.      
  5452.      (define (m . list1)
  5453.        (cond ((neq? (first list1) (term_min list1))
  5454.               (apply m (cyclicrotate list1)))
  5455.              ((term< (last1 list1) (cadr list1))
  5456.               (apply m (reverse (cyclicrotate list1))))
  5457.              (else (cons 'm list1))))
  5458.  
  5459.   Define a procedure to multiply 2 non-numeric elements of the ring.
  5460. Other multiplicatons are handled automatically.  Objects for which rules
  5461. have *not* been defined are not changed.
  5462.  
  5463.      (define (n*n ni nj)
  5464.        (let ((list1 (cdr ni)) (list2 (cdr nj)))
  5465.          (cond ((null? (intersection list1 list2)) #f)
  5466.                ((and (eq? (last1 list1) (first list2))
  5467.                      (neq? (first list1) (last1 list2)))
  5468.                 (apply n (splice list1 list2)))
  5469.                ((and (eq? (first list1) (first list2))
  5470.                      (neq? (last1 list1) (last1 list2)))
  5471.                 (apply n (splice (reverse list1) list2)))
  5472.                ((and (eq? (last1 list1) (last1 list2))
  5473.                      (neq? (first list1) (first list2)))
  5474.                 (apply n (splice list1 (reverse list2))))
  5475.                ((and (eq? (last1 list1) (first list2))
  5476.                      (eq? (first list1) (last1 list2)))
  5477.                 (apply m (cyclicsplice list1 list2)))
  5478.                ((and (eq? (first list1) (first list2))
  5479.                      (eq? (last1 list1) (last1 list2)))
  5480.                 (apply m (cyclicsplice (reverse list1) list2)))
  5481.                (else #f))))
  5482.  
  5483.   Test the procedures to see if they work.
  5484.  
  5485.      ;;; where cyclicrotate(list) is cyclic rotation of the list one step
  5486.      ;;; by putting the first element at the end
  5487.      (define (cyclicrotate list1)
  5488.        (append (rest list1) (list (first list1))))
  5489.      ;;; and where term_min(list) is the element of the list which is
  5490.      ;;; first in the term ordering.
  5491.      (define (term_min list1)
  5492.        (car (sort list1 term<)))
  5493.      (define (term< sym1 sym2)
  5494.        (string<? (symbol->string sym1) (symbol->string sym2)))
  5495.      (define first car)
  5496.      (define rest cdr)
  5497.      (define (last1 list1) (car (last-pair list1)))
  5498.      (define (neq? obj1 obj2) (not (eq? obj1 obj2)))
  5499.      ;;; where splice is the concatenation of list1 and list2 except that their
  5500.      ;;; common element is not repeated.
  5501.      (define (splice list1 list2)
  5502.        (cond ((eq? (last1 list1) (first list2))
  5503.               (append list1 (cdr list2)))
  5504.              (else (error 'splice list1 list2))))
  5505.      ;;; where cyclicsplice is the result of leaving off the last element of
  5506.      ;;; splice(list1,list2).
  5507.      (define (cyclicsplice list1 list2)
  5508.        (cond ((and (eq? (last1 list1) (first list2))
  5509.                    (eq? (first list1) (last1 list2)))
  5510.               (butlast (splice list1 list2) 1))
  5511.              (else (error 'cyclicsplice list1 list2))))
  5512.      
  5513.      (N*N (S a b) (S a b)) => (m a b)
  5514.  
  5515.   Then register the rule for multiplying type N objects by type N
  5516. objects.
  5517.  
  5518.      (cring:define-rule '* 'N 'N N*N))
  5519.  
  5520.   Now we are ready to compute!
  5521.  
  5522.      (define (t)
  5523.        (define detM
  5524.          (+ (* (S g b)
  5525.                (+ (* (S f d)
  5526.                      (- (* (S a f) (S d g)) (* (S a g) (S d f))))
  5527.                   (* (S f f)
  5528.                      (- (* (S a g) (S d d)) (* (S a d) (S d g))))
  5529.                   (* (S f g)
  5530.                      (- (* (S a d) (S d f)) (* (S a f) (S d d))))))
  5531.             (* (S g d)
  5532.                (+ (* (S f b)
  5533.                      (- (* (S a g) (S d f)) (* (S a f) (S d g))))
  5534.                   (* (S f f)
  5535.                      (- (* (S a b) (S d g)) (* (S a g) (S d b))))
  5536.                   (* (S f g)
  5537.                      (- (* (S a f) (S d b)) (* (S a b) (S d f))))))
  5538.             (* (S g f)
  5539.                (+ (* (S f b)
  5540.                      (- (* (S a d) (S d g)) (* (S a g) (S d d))))
  5541.                   (* (S f d)
  5542.                      (- (* (S a g) (S d b)) (* (S a b) (S d g))))
  5543.                   (* (S f g)
  5544.                      (- (* (S a b) (S d d)) (* (S a d) (S d b))))))
  5545.             (* (S g g)
  5546.                (+ (* (S f b)
  5547.                      (- (* (S a f) (S d d)) (* (S a d) (S d f))))
  5548.                   (* (S f d)
  5549.                      (- (* (S a b) (S d f)) (* (S a f) (S d b))))
  5550.                   (* (S f f)
  5551.                      (- (* (S a d) (S d b)) (* (S a b) (S d d))))))))
  5552.        (* (S b e) (S c a) (S e c)
  5553.           detM
  5554.           ))
  5555.      (pretty-print (t))
  5556.      -|
  5557.      (- (+ (m a c e b d f g)
  5558.            (m a c e b d g f)
  5559.            (m a c e b f d g)
  5560.            (m a c e b f g d)
  5561.            (m a c e b g d f)
  5562.            (m a c e b g f d))
  5563.         (* 2 (m a b e c) (m d f g))
  5564.         (* (m a c e b d) (m f g))
  5565.         (* (m a c e b f) (m d g))
  5566.         (* (m a c e b g) (m d f)))
  5567.  
  5568. 
  5569. File: slib.info,  Node: Determinant,  Prev: Commutative Rings,  Up: Mathematical Packages
  5570.  
  5571. Determinant
  5572. ===========
  5573.  
  5574.      (require 'determinant)
  5575.      (determinant '((1 2) (3 4))) => -2
  5576.      (determinant '((1 2 3) (4 5 6) (7 8 9))) => 0
  5577.      (determinant '((1 2 3 4) (5 6 7 8) (9 10 11 12))) => 0
  5578.  
  5579. 
  5580. File: slib.info,  Node: Database Packages,  Next: Other Packages,  Prev: Mathematical Packages,  Up: Top
  5581.  
  5582. Database Packages
  5583. *****************
  5584.  
  5585. * Menu:
  5586.  
  5587. * Base Table::
  5588. * Relational Database::         'relational-database
  5589. * Weight-Balanced Trees::       'wt-tree
  5590.  
  5591. 
  5592. File: slib.info,  Node: Base Table,  Next: Relational Database,  Prev: Database Packages,  Up: Database Packages
  5593.  
  5594. Base Table
  5595. ==========
  5596.  
  5597.   A base table implementation using Scheme association lists is
  5598. available as the value of the identifier `alist-table' after doing:
  5599.  
  5600.   `(require 'alist-table)'
  5601.  
  5602.   Association list base tables are suitable for small databases and
  5603. support all Scheme types when temporary and readable/writeable Scheme
  5604. types when saved.  I hope support for other base table implementations
  5605. will be added in the future.
  5606.  
  5607.   This rest of this section documents the interface for a base table
  5608. implementation from which the *Note Relational Database:: package
  5609. constructs a Relational system.  It will be of interest primarily to
  5610. those wishing to port or write new base-table implementations.
  5611.  
  5612.   All of these functions are accessed through a single procedure by
  5613. calling that procedure with the symbol name of the operation.  A
  5614. procedure will be returned if that operation is supported and `#f'
  5615. otherwise.  For example:
  5616.  
  5617.      (require 'alist-table)
  5618.      (define open-base (alist-table 'make-base))
  5619.      make-base       => *a procedure*
  5620.      (define foo (alist-table 'foo))
  5621.      foo             => #f
  5622.  
  5623.  - Function: make-base FILENAME KEY-DIMENSION COLUMN-TYPES
  5624.      Returns a new, open, low-level database (collection of tables)
  5625.      associated with FILENAME.  This returned database has an empty
  5626.      table associated with CATALOG-ID.  The positive integer
  5627.      KEY-DIMENSION is the number of keys composed to make a PRIMARY-KEY
  5628.      for the catalog table.  The list of symbols COLUMN-TYPES describes
  5629.      the types of each column for that table.  If the database cannot
  5630.      be created as specified, `#f' is returned.
  5631.  
  5632.      Calling the `close-base' method on this database and possibly other
  5633.      operations will cause FILENAME to be written to.  If FILENAME is
  5634.      `#f' a temporary, non-disk based database will be created if such
  5635.      can be supported by the base table implelentation.
  5636.  
  5637.  - Function: open-base FILENAME MUTABLE
  5638.      Returns an open low-level database associated with FILENAME.  If
  5639.      MUTABLE? is `#t', this database will have methods capable of
  5640.      effecting change to the database.  If MUTABLE? is `#f', only
  5641.      methods for inquiring the database will be available.  If the
  5642.      database cannot be opened as specified `#f' is returned.
  5643.  
  5644.      Calling the `close-base' (and possibly other) method on a MUTABLE?
  5645.      database will cause FILENAME to be written to.
  5646.  
  5647.  - Function: write-base LLDB FILENAME
  5648.      Causes the low-level database LLDB to be written to FILENAME.  If
  5649.      the write is successful, also causes LLDB to henceforth be
  5650.      associated with FILENAME.  Calling the `close-database' (and
  5651.      possibly other) method on LLDB may cause FILENAME to be written
  5652.      to.  If FILENAME is `#f' this database will be changed to a
  5653.      temporary, non-disk based database if such can be supported by the
  5654.      underlying base table implelentation.  If the operations completed
  5655.      successfully, `#t' is returned.  Otherwise, `#f' is returned.
  5656.  
  5657.  - Function: sync-base LLDB
  5658.      Causes the file associated with the low-level database LLDB to be
  5659.      updated to reflect its current state.  If the associated filename
  5660.      is `#f', no action is taken and `#f' is returned.  If this
  5661.      operation completes successfully, `#t' is returned.  Otherwise,
  5662.      `#f' is returned.
  5663.  
  5664.  - Function: close-base LLDB
  5665.      Causes the low-level database LLDB to be written to its associated
  5666.      file (if any).  If the write is successful, subsequent operations
  5667.      to LLDB will signal an error.  If the operations complete
  5668.      successfully, `#t' is returned.  Otherwise, `#f' is returned.
  5669.  
  5670.  - Function: make-table LLDB KEY-DIMENSION COLUMN-TYPES
  5671.      Returns the BASE-ID for a new base table, otherwise returns `#f'.
  5672.      The base table can then be opened using `(open-table LLDB
  5673.      BASE-ID)'.  The positive integer KEY-DIMENSION is the number of
  5674.      keys composed to make a PRIMARY-KEY for this table.  The list of
  5675.      symbols COLUMN-TYPES describes the types of each column.
  5676.  
  5677.  - Constant: catalog-id
  5678.      A constant BASE-ID suitable for passing as a parameter to
  5679.      `open-table'.  CATALOG-ID will be used as the base table for the
  5680.      system catalog.
  5681.  
  5682.  - Function: open-table LLDB BASE-ID KEY-DIMENSION COLUMN-TYPES
  5683.      Returns a HANDLE for an existing base table in the low-level
  5684.      database LLDB if that table exists and can be opened in the mode
  5685.      indicated by MUTABLE?, otherwise returns `#f'.
  5686.  
  5687.      As with `make-table', the positive integer KEY-DIMENSION is the
  5688.      number of keys composed to make a PRIMARY-KEY for this table.  The
  5689.      list of symbols COLUMN-TYPES describes the types of each column.
  5690.  
  5691.  - Function: kill-table LLDB BASE-ID KEY-DIMENSION COLUMN-TYPES
  5692.      Returns `#t' if the base table associated with BASE-ID was removed
  5693.      from the low level database LLDB, and `#f' otherwise.
  5694.  
  5695.  - Function: make-keyifier-1 TYPE
  5696.      Returns a procedure which accepts a single argument which must be
  5697.      of type TYPE.  This returned procedure returns an object suitable
  5698.      for being a KEY argument in the functions whose descriptions
  5699.      follow.
  5700.  
  5701.      Any 2 arguments of the supported type passed to the returned
  5702.      function which are not `equal?' must result in returned values
  5703.      which are not `equal?'.
  5704.  
  5705.  - Function: make-list-keyifier KEY-DIMENSION TYPES
  5706.      The list of symbols TYPES must have at least KEY-DIMENSION
  5707.      elements.  Returns a procedure which accepts a list of length
  5708.      KEY-DIMENSION and whose types must corresopond to the types named
  5709.      by TYPES.  This returned procedure combines the elements of its
  5710.      list argument into an object suitable for being a KEY argument in
  5711.      the functions whose descriptions follow.
  5712.  
  5713.      Any 2 lists of supported types (which must at least include
  5714.      symbols and non-negative integers) passed to the returned function
  5715.      which are not `equal?' must result in returned values which are not
  5716.      `equal?'.
  5717.  
  5718.  - Function: make-key-extractor KEY-DIMENSION TYPES COLUMN-NUMBER
  5719.      Returns a procedure which accepts objects produced by application
  5720.      of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'.  This
  5721.      procedure returns a KEY which is `equal?' to the COLUMN-NUMBERth
  5722.      element of the list which was passed to create COMBINED-KEY.  The
  5723.      list TYPES must have at least KEY-DIMENSION elements.
  5724.  
  5725.  - Function: make-key->list KEY-DIMENSION TYPES
  5726.      Returns a procedure which accepts objects produced by application
  5727.      of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'.  This
  5728.      procedure returns a list of KEYs which are elementwise `equal?' to
  5729.      the list which was passed to create COMBINED-KEY.
  5730.  
  5731. In the following functions, the KEY argument can always be assumed to
  5732. be the value returned by a call to a *keyify* routine.
  5733.  
  5734. In contrast, a MATCH-KEYS argument is a list of length equal to the           |
  5735. number of primary keys.  The MATCH-KEYS restrict the actions of the           |
  5736. table command to those records whose primary keys all satisfy the
  5737. corresponding element of the MATCH-KEYS list.  The elements and their         |
  5738. actions are:
  5739.  
  5740.     `#f'
  5741.           The false value matches any key in the corresponding position.
  5742.  
  5743.     an object of type procedure
  5744.           This procedure must take a single argument, the key in the
  5745.           corresponding position.  Any key for which the procedure
  5746.           returns a non-false value is a match; Any key for which the
  5747.           procedure returns a `#f' is not.
  5748.  
  5749.     other values
  5750.           Any other value matches only those keys `equal?' to it.
  5751.  
  5752. The KEY-DIMENSION and COLUMN-TYPES arguments are needed to decode the         |
  5753. combined-keys for matching with MATCH-KEYS.                                   |
  5754.                                                                               |
  5755.  - Function: for-each-key HANDLE PROCEDURE KEY-DIMENSION COLUMN-TYPES         |
  5756.           MATCH-KEYS                                                          |
  5757.      Calls PROCEDURE once with each KEY in the table opened in HANDLE
  5758.      which satisfy MATCH-KEYS in an unspecified order.  An unspecified        |
  5759.      value is returned.
  5760.  
  5761.  - Function: map-key HANDLE PROCEDURE KEY-DIMENSION COLUMN-TYPES              |
  5762.           MATCH-KEYS                                                          |
  5763.      Returns a list of the values returned by calling PROCEDURE once
  5764.      with each KEY in the table opened in HANDLE which satisfy                |
  5765.      MATCH-KEYS in an unspecified order.                                      |
  5766.  
  5767.  - Function: ordered-for-each-key HANDLE PROCEDURE KEY-DIMENSION              |
  5768.           COLUMN-TYPES MATCH-KEYS                                             |
  5769.      Calls PROCEDURE once with each KEY in the table opened in HANDLE
  5770.      which satisfy MATCH-KEYS in the natural order for the types of the       |
  5771.      primary key fields of that table.  An unspecified value is               |
  5772.      returned.
  5773.  
  5774.  - Function: delete* HANDLE KEY-DIMENSION COLUMN-TYPES MATCH-KEYS             |
  5775.      Removes all rows which satisfy MATCH-KEYS from the table opened in       |
  5776.      HANDLE.  An unspecified value is returned.
  5777.  
  5778.  - Function: present? HANDLE KEY
  5779.      Returns a non-`#f' value if there is a row associated with KEY in
  5780.      the table opened in HANDLE and `#f' otherwise.
  5781.  
  5782.  - Function: delete HANDLE KEY
  5783.      Removes the row associated with KEY from the table opened in
  5784.      HANDLE.  An unspecified value is returned.
  5785.  
  5786.  - Function: make-getter KEY-DIMENSION TYPES
  5787.      Returns a procedure which takes arguments HANDLE and KEY.  This
  5788.      procedure returns a list of the non-primary values of the relation
  5789.      (in the base table opened in HANDLE) whose primary key is KEY if
  5790.      it exists, and `#f' otherwise.
  5791.  
  5792.  - Function: make-putter KEY-DIMENSION TYPES
  5793.      Returns a procedure which takes arguments HANDLE and KEY and
  5794.      VALUE-LIST.  This procedure associates the primary key KEY with
  5795.      the values in VALUE-LIST (in the base table opened in HANDLE) and
  5796.      returns an unspecified value.
  5797.  
  5798.  - Function: supported-type? SYMBOL
  5799.      Returns `#t' if SYMBOL names a type allowed as a column value by
  5800.      the implementation, and `#f' otherwise.  At a minimum, an
  5801.      implementation must support the types `integer', `symbol',
  5802.      `string', `boolean', and `base-id'.
  5803.  
  5804.  - Function: supported-key-type? SYMBOL
  5805.      Returns `#t' if SYMBOL names a type allowed as a key value by the
  5806.      implementation, and `#f' otherwise.  At a minimum, an
  5807.      implementation must support the types `integer', and `symbol'.
  5808.  
  5809. `integer'
  5810.      Scheme exact integer.
  5811.  
  5812. `symbol'
  5813.      Scheme symbol.
  5814.  
  5815. `boolean'
  5816.      `#t' or `#f'.
  5817.  
  5818. `base-id'
  5819.      Objects suitable for passing as the BASE-ID parameter to
  5820.      `open-table'.  The value of CATALOG-ID must be an acceptable
  5821.      `base-id'.
  5822.  
  5823. 
  5824. File: slib.info,  Node: Relational Database,  Next: Weight-Balanced Trees,  Prev: Base Table,  Up: Database Packages
  5825.  
  5826. Relational Database
  5827. ===================
  5828.  
  5829.   `(require 'relational-database)'
  5830.  
  5831.   This package implements a database system inspired by the Relational
  5832. Model (`E. F. Codd, A Relational Model of Data for Large Shared Data
  5833. Banks').  An SLIB relational database implementation can be created
  5834. from any *Note Base Table:: implementation.
  5835.  
  5836. * Menu:
  5837.  
  5838. * Motivations::                 Database Manifesto
  5839. * Creating and Opening Relational Databases::
  5840. * Relational Database Operations::
  5841. * Table Operations::
  5842. * Catalog Representation::
  5843. * Unresolved Issues::
  5844. * Database Utilities::          'database-utilities
  5845. * Database Reports::
  5846. * Database Browser::            'database-browse
  5847.  
  5848. 
  5849. File: slib.info,  Node: Motivations,  Next: Creating and Opening Relational Databases,  Prev: Relational Database,  Up: Relational Database
  5850.  
  5851. Motivations
  5852. -----------
  5853.  
  5854.   Most nontrivial programs contain databases: Makefiles, configure
  5855. scripts, file backup, calendars, editors, source revision control, CAD
  5856. systems, display managers, menu GUIs, games, parsers, debuggers,
  5857. profilers, and even error reporting are all rife with databases.  Coding
  5858. databases is such a common activity in programming that many may not be
  5859. aware of how often they do it.
  5860.  
  5861.   A database often starts as a dispatch in a program.  The author,
  5862. perhaps because of the need to make the dispatch configurable, the need
  5863. for correlating dispatch in other routines, or because of changes or
  5864. growth, devises a data structure to contain the information, a routine
  5865. for interpreting that data structure, and perhaps routines for
  5866. augmenting and modifying the stored data.  The dispatch must be
  5867. converted into this form and tested.
  5868.  
  5869.   The programmer may need to devise an interactive program for enabling
  5870. easy examination and modification of the information contained in this
  5871. database.  Often, in an attempt to foster modularity and avoid delays in
  5872. release, intermediate file formats for the database information are
  5873. devised.  It often turns out that users prefer modifying these
  5874. intermediate files with a text editor to using the interactive program
  5875. in order to do operations (such as global changes) not forseen by the
  5876. program's author.
  5877.  
  5878.   In order to address this need, the conscientious software engineer may
  5879. even provide a scripting language to allow users to make repetitive
  5880. database changes.  Users will grumble that they need to read a large
  5881. manual and learn yet another programming language (even if it *almost*
  5882. has language "xyz" syntax) in order to do simple configuration.
  5883.  
  5884.   All of these facilities need to be designed, coded, debugged,
  5885. documented, and supported; often causing what was very simple in concept
  5886. to become a major developement project.
  5887.  
  5888.   This view of databases just outlined is somewhat the reverse of the
  5889. view of the originators of the "Relational Model" of database
  5890. abstraction.  The relational model was devised to unify and allow
  5891. interoperation of large multi-user databases running on diverse
  5892. platforms.  A fairly general purpose "Comprehensive Language" for
  5893. database manipulations is mandated (but not specified) as part of the
  5894. relational model for databases.
  5895.  
  5896.   One aspect of the Relational Model of some importance is that the
  5897. "Comprehensive Language" must be expressible in some form which can be
  5898. stored in the database.  This frees the programmer from having to make
  5899. programs data-driven in order to use a database.
  5900.  
  5901.   This package includes as one of its basic supported types Scheme
  5902. "expression"s.  This type allows expressions as defined by the Scheme
  5903. standards to be stored in the database.  Using `slib:eval' retrieved
  5904. expressions can be evaluated (in the top-level environment).  Scheme's
  5905. `lambda' facilitates closure of environments, modularity, etc. so that
  5906. procedures (which could not be stored directly most databases) can
  5907. still be effectively retrieved.  Since `slib:eval' evaluates
  5908. expressions in the top-level environment, built-in and user defined
  5909. procedures can be easily accessed by name.
  5910.  
  5911.   This package's purpose is to standardize (through a common interface)
  5912. database creation and usage in Scheme programs.  The relational model's
  5913. provision for inclusion of language expressions as data as well as the
  5914. description (in tables, of course) of all of its tables assures that
  5915. relational databases are powerful enough to assume the roles currently
  5916. played by thousands of ad-hoc routines and data formats.
  5917.  
  5918. Such standardization to a relational-like model brings many benefits:
  5919.  
  5920.    * Tables, fields, domains, and types can be dealt with by name in
  5921.      programs.
  5922.  
  5923.    * The underlying database implementation can be changed (for
  5924.      performance or other reasons) by changing a single line of code.
  5925.  
  5926.    * The formats of tables can be easily extended or changed without
  5927.      altering code.
  5928.  
  5929.    * Consistency checks are specified as part of the table descriptions.
  5930.      Changes in checks need only occur in one place.
  5931.  
  5932.    * All the configuration information which the developer wishes to
  5933.      group together is easily grouped, without needing to change
  5934.      programs aware of only some of these tables.
  5935.  
  5936.    * Generalized report generators, interactive entry programs, and
  5937.      other database utilities can be part of a shared library.  The
  5938.      burden of adding configurability to a program is greatly reduced.
  5939.  
  5940.    * Scheme is the "comprehensive language" for these databases.
  5941.      Scripting for configuration no longer needs to be in a separate
  5942.      language with additional documentation.
  5943.  
  5944.    * Scheme's latent types mesh well with the strict typing and logical
  5945.      requirements of the relational model.
  5946.  
  5947.    * Portable formats allow easy interchange of data.  The included
  5948.      table descriptions help prevent misinterpretation of format.
  5949.  
  5950. 
  5951. File: slib.info,  Node: Creating and Opening Relational Databases,  Next: Relational Database Operations,  Prev: Motivations,  Up: Relational Database
  5952.  
  5953. Creating and Opening Relational Databases
  5954. -----------------------------------------
  5955.  
  5956.  - Function: make-relational-system BASE-TABLE-IMPLEMENTATION
  5957.      Returns a procedure implementing a relational database using the
  5958.      BASE-TABLE-IMPLEMENTATION.
  5959.  
  5960.      All of the operations of a base table implementation are accessed
  5961.      through a procedure defined by `require'ing that implementation.
  5962.      Similarly, all of the operations of the relational database
  5963.      implementation are accessed through the procedure returned by
  5964.      `make-relational-system'.  For instance, a new relational database
  5965.      could be created from the procedure returned by
  5966.      `make-relational-system' by:
  5967.  
  5968.           (require 'alist-table)
  5969.           (define relational-alist-system
  5970.                   (make-relational-system alist-table))
  5971.           (define create-alist-database
  5972.                   (relational-alist-system 'create-database))
  5973.           (define my-database
  5974.                   (create-alist-database "mydata.db"))
  5975.  
  5976. What follows are the descriptions of the methods available from
  5977. relational system returned by a call to `make-relational-system'.
  5978.  
  5979.  - Function: create-database FILENAME
  5980.      Returns an open, nearly empty relational database associated with
  5981.      FILENAME.  The only tables defined are the system catalog and
  5982.      domain table.  Calling the `close-database' method on this database
  5983.      and possibly other operations will cause FILENAME to be written
  5984.      to.  If FILENAME is `#f' a temporary, non-disk based database will
  5985.      be created if such can be supported by the underlying base table
  5986.      implelentation.  If the database cannot be created as specified
  5987.      `#f' is returned.  For the fields and layout of descriptor tables,
  5988.      *Note Catalog Representation::
  5989.  
  5990.  - Function: open-database FILENAME MUTABLE?
  5991.      Returns an open relational database associated with FILENAME.  If
  5992.      MUTABLE? is `#t', this database will have methods capable of
  5993.      effecting change to the database.  If MUTABLE? is `#f', only
  5994.      methods for inquiring the database will be available.  Calling the
  5995.      `close-database' (and possibly other) method on a MUTABLE?
  5996.      database will cause FILENAME to be written to.  If the database
  5997.      cannot be opened as specified `#f' is returned.
  5998.  
  5999. 
  6000. File: slib.info,  Node: Relational Database Operations,  Next: Table Operations,  Prev: Creating and Opening Relational Databases,  Up: Relational Database
  6001.  
  6002. Relational Database Operations
  6003. ------------------------------
  6004.  
  6005. These are the descriptions of the methods available from an open
  6006. relational database.  A method is retrieved from a database by calling
  6007. the database with the symbol name of the operation.  For example:
  6008.  
  6009.      (define my-database
  6010.              (create-alist-database "mydata.db"))
  6011.      (define telephone-table-desc
  6012.              ((my-database 'create-table) 'telephone-table-desc))
  6013.  
  6014.  - Function: close-database
  6015.      Causes the relational database to be written to its associated
  6016.      file (if any).  If the write is successful, subsequent operations
  6017.      to this database will signal an error.  If the operations completed
  6018.      successfully, `#t' is returned.  Otherwise, `#f' is returned.
  6019.  
  6020.  - Function: write-database FILENAME
  6021.      Causes the relational database to be written to FILENAME.  If the
  6022.      write is successful, also causes the database to henceforth be
  6023.      associated with FILENAME.  Calling the `close-database' (and
  6024.      possibly other) method on this database will cause FILENAME to be
  6025.      written to.  If FILENAME is `#f' this database will be changed to
  6026.      a temporary, non-disk based database if such can be supported by
  6027.      the underlying base table implelentation.  If the operations
  6028.      completed successfully, `#t' is returned.  Otherwise, `#f' is
  6029.      returned.
  6030.  
  6031.  - Function: table-exists? TABLE-NAME
  6032.      Returns `#t' if TABLE-NAME exists in the system catalog, otherwise
  6033.      returns `#f'.
  6034.  
  6035.  - Function: open-table TABLE-NAME MUTABLE?
  6036.      Returns a "methods" procedure for an existing relational table in
  6037.      this database if it exists and can be opened in the mode indicated
  6038.      by MUTABLE?, otherwise returns `#f'.
  6039.  
  6040. These methods will be present only in databases which are MUTABLE?.
  6041.  
  6042.  - Function: delete-table TABLE-NAME
  6043.      Removes and returns the TABLE-NAME row from the system catalog if
  6044.      the table or view associated with TABLE-NAME gets removed from the
  6045.      database, and `#f' otherwise.
  6046.  
  6047.  - Function: create-table TABLE-DESC-NAME
  6048.      Returns a methods procedure for a new (open) relational table for
  6049.      describing the columns of a new base table in this database,
  6050.      otherwise returns `#f'.  For the fields and layout of descriptor
  6051.      tables, *Note Catalog Representation::.
  6052.  
  6053.  - Function: create-table TABLE-NAME TABLE-DESC-NAME
  6054.      Returns a methods procedure for a new (open) relational table with
  6055.      columns as described by TABLE-DESC-NAME, otherwise returns `#f'.
  6056.  
  6057.  - Function: create-view ??
  6058.  - Function: project-table ??
  6059.  - Function: restrict-table ??
  6060.  - Function: cart-prod-tables ??
  6061.      Not yet implemented.
  6062.  
  6063. 
  6064. File: slib.info,  Node: Table Operations,  Next: Catalog Representation,  Prev: Relational Database Operations,  Up: Relational Database
  6065.  
  6066. Table Operations
  6067. ----------------
  6068.  
  6069. These are the descriptions of the methods available from an open
  6070. relational table.  A method is retrieved from a table by calling the
  6071. table with the symbol name of the operation.  For example:
  6072.  
  6073.      (define telephone-table-desc
  6074.              ((my-database 'create-table) 'telephone-table-desc))
  6075.      (require 'common-list-functions)
  6076.      (define ndrp (telephone-table-desc 'row:insert))
  6077.      (ndrp '(1 #t name #f string))
  6078.      (ndrp '(2 #f telephone
  6079.                (lambda (d)
  6080.                  (and (string? d) (> (string-length d) 2)
  6081.                       (every
  6082.                        (lambda (c)
  6083.                          (memv c '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9
  6084.                                        #\+ #\( #\  #\) #\-)))
  6085.                        (string->list d))))
  6086.                string))
  6087.  
  6088. Some operations described below require primary key arguments.  Primary
  6089. keys arguments are denoted KEY1 KEY2 ....  It is an error to call an
  6090. operation for a table which takes primary key arguments with the wrong
  6091. number of primary keys for that table.
  6092.  
  6093. The term "row" used below refers to a Scheme list of values (one for
  6094. each column) in the order specified in the descriptor (table) for this
  6095. table.  Missing values appear as `#f'.  Primary keys must not be
  6096. missing.
  6097.  
  6098.  - Function: get COLUMN-NAME
  6099.      Returns a procedure of arguments KEY1 KEY2 ... which returns the
  6100.      value for the COLUMN-NAME column of the row associated with
  6101.      primary keys KEY1, KEY2 ... if that row exists in the table, or
  6102.      `#f' otherwise.
  6103.  
  6104.           ((plat 'get 'processor) 'djgpp) => i386
  6105.           ((plat 'get 'processor) 'be-os) => #f
  6106.  
  6107.  - Function: get* COLUMN-NAME
  6108.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  6109.      returns a list of the values for the specified column for all rows
  6110.      in this table.  The optional MATCH-KEY1 ... arguments restrict
  6111.      actions to a subset of the table.  See the match-key description
  6112.      below for details.
  6113.  
  6114.           ((plat 'get* 'processor)) =>
  6115.           (i386 8086 i386 8086 i386 i386 8086 m68000
  6116.            m68000 m68000 m68000 m68000 powerpc)
  6117.           
  6118.           ((plat 'get* 'processor) #f) =>
  6119.           (i386 8086 i386 8086 i386 i386 8086 m68000
  6120.            m68000 m68000 m68000 m68000 powerpc)
  6121.           
  6122.           (define (a-key? key)
  6123.              (char=? #\a (string-ref (symbol->string key) 0)))
  6124.           
  6125.           ((plat 'get* 'processor) a-key?) =>
  6126.           (m68000 m68000 m68000 m68000 m68000 powerpc)
  6127.           
  6128.           ((plat 'get* 'name) a-key?) =>
  6129.           (atari-st-turbo-c atari-st-gcc amiga-sas/c-5.10
  6130.            amiga-aztec amiga-dice-c aix)
  6131.  
  6132.  - Function: row:retrieve
  6133.      Returns a procedure of arguments KEY1 KEY2 ... which returns the
  6134.      row associated with primary keys KEY1, KEY2 ... if it exists, or
  6135.      `#f' otherwise.
  6136.  
  6137.           ((plat 'row:retrieve) 'linux) => (linux i386 linux gcc)
  6138.           ((plat 'row:retrieve) 'multics) => #f
  6139.  
  6140.  - Function: row:retrieve*
  6141.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  6142.      returns a list of all rows in this table.  The optional MATCH-KEY1
  6143.      ... arguments restrict actions to a subset of the table.  See the
  6144.      match-key description below for details.
  6145.  
  6146.      ((plat 'row:retrieve*) a-key?) =>
  6147.      ((atari-st-turbo-c m68000 atari turbo-c)
  6148.       (atari-st-gcc m68000 atari gcc)
  6149.       (amiga-sas/c-5.10 m68000 amiga sas/c)
  6150.       (amiga-aztec m68000 amiga aztec)
  6151.       (amiga-dice-c m68000 amiga dice-c)
  6152.       (aix powerpc aix -))
  6153.  
  6154.  - Function: row:remove
  6155.      Returns a procedure of arguments KEY1 KEY2 ... which removes and
  6156.      returns the row associated with primary keys KEY1, KEY2 ... if it
  6157.      exists, or `#f' otherwise.
  6158.  
  6159.  - Function: row:remove*
  6160.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  6161.      removes and returns a list of all rows in this table.  The optional
  6162.      MATCH-KEY1 ... arguments restrict actions to a subset of the
  6163.      table.  See the match-key description below for details.
  6164.  
  6165.  - Function: row:delete
  6166.      Returns a procedure of arguments KEY1 KEY2 ... which deletes the
  6167.      row associated with primary keys KEY1, KEY2 ... if it exists.  The
  6168.      value returned is unspecified.
  6169.  
  6170.  - Function: row:delete*
  6171.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  6172.      Deletes all rows from this table.  The optional MATCH-KEY1 ...
  6173.      arguments restrict deletions to a subset of the table.  See the
  6174.      match-key description below for details.  The value returned is
  6175.      unspecified.  The descriptor table and catalog entry for this
  6176.      table are not affected.
  6177.  
  6178.  - Function: row:update
  6179.      Returns a procedure of one argument, ROW, which adds the row, ROW,
  6180.      to this table.  If a row for the primary key(s) specified by ROW
  6181.      already exists in this table, it will be overwritten.  The value
  6182.      returned is unspecified.
  6183.  
  6184.  - Function: row:update*
  6185.      Returns a procedure of one argument, ROWS, which adds each row in
  6186.      the list of rows, ROWS, to this table.  If a row for the primary
  6187.      key specified by an element of ROWS already exists in this table,
  6188.      it will be overwritten.  The value returned is unspecified.
  6189.  
  6190.  - Function: row:insert
  6191.      Adds the row ROW to this table.  If a row for the primary key(s)
  6192.      specified by ROW already exists in this table an error is
  6193.      signaled.  The value returned is unspecified.
  6194.  
  6195.  - Function: row:insert*
  6196.      Returns a procedure of one argument, ROWS, which adds each row in
  6197.      the list of rows, ROWS, to this table.  If a row for the primary
  6198.      key specified by an element of ROWS already exists in this table,
  6199.      an error is signaled.  The value returned is unspecified.
  6200.  
  6201.  - Function: for-each-row
  6202.      Returns a procedure of arguments PROC MATCH-KEY1 ...  which calls
  6203.      PROC with each ROW in this table in the (implementation-dependent)
  6204.      natural ordering for rows.  The optional MATCH-KEY1 ... arguments
  6205.      restrict actions to a subset of the table.  See the match-key
  6206.      description below for details.
  6207.  
  6208.      *Real* relational programmers would use some least-upper-bound join
  6209.      for every row to get them in order; But we don't have joins yet.
  6210.  
  6211. The (optional) MATCH-KEY1 ... arguments are used to restrict actions of
  6212. a whole-table operation to a subset of that table.  Those procedures
  6213. (returned by methods) which accept match-key arguments will accept any
  6214. number of match-key arguments between zero and the number of primary
  6215. keys in the table.  Any unspecified MATCH-KEY arguments default to `#f'.
  6216.  
  6217. The MATCH-KEY1 ... restrict the actions of the table command to those
  6218. records whose primary keys each satisfy the corresponding MATCH-KEY
  6219. argument.  The arguments and their actions are:
  6220.  
  6221.     `#f'
  6222.           The false value matches any key in the corresponding position.
  6223.  
  6224.     an object of type procedure
  6225.           This procedure must take a single argument, the key in the
  6226.           corresponding position.  Any key for which the procedure
  6227.           returns a non-false value is a match; Any key for which the
  6228.           procedure returns a `#f' is not.
  6229.  
  6230.     other values
  6231.           Any other value matches only those keys `equal?' to it.
  6232.  
  6233.  - Function: close-table
  6234.      Subsequent operations to this table will signal an error.
  6235.  
  6236.  - Constant: column-names
  6237.  - Constant: column-foreigns
  6238.  - Constant: column-domains
  6239.  - Constant: column-types
  6240.      Return a list of the column names, foreign-key table names, domain
  6241.      names, or type names respectively for this table.  These 4 methods
  6242.      are different from the others in that the list is returned, rather
  6243.      than a procedure to obtain the list.
  6244.  
  6245.  - Constant: primary-limit
  6246.      Returns the number of primary keys fields in the relations in this
  6247.      table.
  6248.  
  6249. 
  6250. File: slib.info,  Node: Catalog Representation,  Next: Unresolved Issues,  Prev: Table Operations,  Up: Relational Database
  6251.  
  6252. Catalog Representation
  6253. ----------------------
  6254.  
  6255. Each database (in an implementation) has a "system catalog" which
  6256. describes all the user accessible tables in that database (including
  6257. itself).
  6258.  
  6259. The system catalog base table has the following fields.  `PRI'
  6260. indicates a primary key for that table.
  6261.  
  6262.      PRI table-name
  6263.          column-limit            the highest column number
  6264.          coltab-name             descriptor table name
  6265.          bastab-id               data base table identifier
  6266.          user-integrity-rule
  6267.          view-procedure          A scheme thunk which, when called,
  6268.                                  produces a handle for the view.  coltab
  6269.                                  and bastab are specified if and only if
  6270.                                  view-procedure is not.
  6271.  
  6272. Descriptors for base tables (not views) are tables (pointed to by
  6273. system catalog).  Descriptor (base) tables have the fields:
  6274.  
  6275.      PRI column-number           sequential integers from 1
  6276.          primary-key?            boolean TRUE for primary key components
  6277.          column-name
  6278.          column-integrity-rule
  6279.          domain-name
  6280.  
  6281. A "primary key" is any column marked as `primary-key?' in the
  6282. corresponding descriptor table.  All the `primary-key?' columns must
  6283. have lower column numbers than any non-`primary-key?' columns.  Every
  6284. table must have at least one primary key.  Primary keys must be
  6285. sufficient to distinguish all rows from each other in the table.  All of
  6286. the system defined tables have a single primary key.
  6287.  
  6288. This package currently supports tables having from 1 to 4 primary keys
  6289. if there are non-primary columns, and any (natural) number if *all*
  6290. columns are primary keys.  If you need more than 4 primary keys, I would
  6291. like to hear what you are doing!
  6292.  
  6293. A "domain" is a category describing the allowable values to occur in a
  6294. column.  It is described by a (base) table with the fields:
  6295.  
  6296.      PRI domain-name
  6297.          foreign-table
  6298.          domain-integrity-rule
  6299.          type-id
  6300.          type-param
  6301.  
  6302. The "type-id" field value is a symbol.  This symbol may be used by the
  6303. underlying base table implementation in storing that field.
  6304.  
  6305. If the `foreign-table' field is non-`#f' then that field names a table
  6306. from the catalog.  The values for that domain must match a primary key
  6307. of the table referenced by the TYPE-PARAM (or `#f', if allowed).  This
  6308. package currently does not support composite foreign-keys.
  6309.  
  6310. The types for which support is planned are:
  6311.          atom
  6312.          symbol
  6313.          string                  [<length>]
  6314.          number                  [<base>]
  6315.          money                   <currency>
  6316.          date-time
  6317.          boolean
  6318.      
  6319.          foreign-key             <table-name>
  6320.          expression
  6321.          virtual                 <expression>
  6322.  
  6323. 
  6324. File: slib.info,  Node: Unresolved Issues,  Next: Database Utilities,  Prev: Catalog Representation,  Up: Relational Database
  6325.  
  6326. Unresolved Issues
  6327. -----------------
  6328.  
  6329.   Although `rdms.scm' is not large, I found it very difficult to write
  6330. (six rewrites).  I am not aware of any other examples of a generalized
  6331. relational system (although there is little new in CS).  I left out
  6332. several aspects of the Relational model in order to simplify the job.
  6333. The major features lacking (which might be addressed portably) are
  6334. views, transaction boundaries, and protection.
  6335.  
  6336.   Protection needs a model for specifying priveledges.  Given how
  6337. operations are accessed from handles it should not be difficult to
  6338. restrict table accesses to those allowed for that user.
  6339.  
  6340.   The system catalog has a field called `view-procedure'.  This should
  6341. allow a purely functional implementation of views.  This will work but
  6342. is unsatisfying for views resulting from a "select"ion (subset of
  6343. rows); for whole table operations it will not be possible to reduce the
  6344. number of keys scanned over when the selection is specified only by an
  6345. opaque procedure.
  6346.  
  6347.   Transaction boundaries present the most intriguing area.  Transaction
  6348. boundaries are actually a feature of the "Comprehensive Language" of the
  6349. Relational database and not of the database.  Scheme would seem to
  6350. provide the opportunity for an extremely clean semantics for transaction
  6351. boundaries since the builtin procedures with side effects are small in
  6352. number and easily identified.
  6353.  
  6354.   These side-effect builtin procedures might all be portably redefined
  6355. to versions which properly handled transactions.  Compiled library
  6356. routines would need to be recompiled as well.  Many system extensions
  6357. (delete-file, system, etc.) would also need to be redefined.
  6358.  
  6359. There are 2 scope issues that must be resolved for multiprocess
  6360. transaction boundaries:
  6361.  
  6362. Process scope
  6363.      The actions captured by a transaction should be only for the
  6364.      process which invoked the start of transaction.  Although standard
  6365.      Scheme does not provide process primitives as such, `dynamic-wind'
  6366.      would provide a workable hook into process switching for many
  6367.      implementations.
  6368.  
  6369. Shared utilities with state
  6370.      Some shared utilities have state which should *not* be part of a
  6371.      transaction.  An example would be calling a pseudo-random number
  6372.      generator.  If the success of a transaction depended on the
  6373.      pseudo-random number and failed, the state of the generator would
  6374.      be set back.  Subsequent calls would keep returning the same
  6375.      number and keep failing.
  6376.  
  6377.      Pseudo-random number generators are not reentrant; thus they would
  6378.      require locks in order to operate properly in a multiprocess
  6379.      environment.  Are all examples of utilities whose state should not
  6380.      be part of transactions also non-reentrant?  If so, perhaps
  6381.      suspending transaction capture for the duration of locks would
  6382.      solve this problem.
  6383.  
  6384. 
  6385. File: slib.info,  Node: Database Utilities,  Next: Database Reports,  Prev: Unresolved Issues,  Up: Relational Database
  6386.  
  6387. Database Utilities
  6388. ------------------
  6389.  
  6390.   `(require 'database-utilities)'
  6391.  
  6392. This enhancement wraps a utility layer on `relational-database' which
  6393. provides:
  6394.    * Automatic loading of the appropriate base-table package when
  6395.      opening a database.
  6396.  
  6397.    * Automatic execution of initialization commands stored in database.
  6398.  
  6399.    * Transparent execution of database commands stored in `*commands*'
  6400.      table in database.
  6401.  
  6402. Also included are utilities which provide:
  6403.    * Data definition from Scheme lists and
  6404.  
  6405.    * Report generation
  6406.  
  6407. for any SLIB relational database.
  6408.  
  6409.  - Function: create-database FILENAME BASE-TABLE-TYPE
  6410.      Returns an open, nearly empty enhanced (with `*commands*' table)
  6411.      relational database (with base-table type BASE-TABLE-TYPE)
  6412.      associated with FILENAME.
  6413.  
  6414.  - Function: open-database FILENAME
  6415.  - Function: open-database FILENAME BASE-TABLE-TYPE
  6416.      Returns an open enchanced relational database associated with
  6417.      FILENAME.  The database will be opened with base-table type
  6418.      BASE-TABLE-TYPE) if supplied.  If BASE-TABLE-TYPE is not supplied,
  6419.      `open-database' will attempt to deduce the correct
  6420.      base-table-type.  If the database can not be opened or if it lacks
  6421.      the `*commands*' table, `#f' is returned.
  6422.  
  6423.  - Function: open-database! FILENAME
  6424.  - Function: open-database! FILENAME BASE-TABLE-TYPE
  6425.      Returns *mutable* open enchanced relational database ...
  6426.  
  6427. The table `*commands*' in an "enhanced" relational-database has the
  6428. fields (with domains):
  6429.      PRI name        symbol
  6430.          parameters  parameter-list
  6431.          procedure   expression
  6432.          documentation string
  6433.  
  6434.   The `parameters' field is a foreign key (domain `parameter-list') of
  6435. the `*catalog-data*' table and should have the value of a table
  6436. described by `*parameter-columns*'.  This `parameter-list' table
  6437. describes the arguments suitable for passing to the associated command.
  6438. The intent of this table is to be of a form such that different
  6439. user-interfaces (for instance, pull-down menus or plain-text queries)
  6440. can operate from the same table.  A `parameter-list' table has the
  6441. following fields:
  6442.      PRI index       uint
  6443.          name        symbol
  6444.          arity       parameter-arity
  6445.          domain      domain
  6446.          defaulter   expression
  6447.          expander    expression
  6448.          documentation string
  6449.  
  6450.   The `arity' field can take the values:
  6451.  
  6452. `single'
  6453.      Requires a single parameter of the specified domain.
  6454.  
  6455. `optional'
  6456.      A single parameter of the specified domain or zero parameters is
  6457.      acceptable.
  6458.  
  6459. `boolean'
  6460.      A single boolean parameter or zero parameters (in which case `#f'
  6461.      is substituted) is acceptable.
  6462.  
  6463. `nary'
  6464.      Any number of parameters of the specified domain are acceptable.
  6465.      The argument passed to the command function is always a list of the
  6466.      parameters.
  6467.  
  6468. `nary1'
  6469.      One or more of parameters of the specified domain are acceptable.
  6470.      The argument passed to the command function is always a list of the
  6471.      parameters.
  6472.  
  6473.   The `domain' field specifies the domain which a parameter or
  6474. parameters in the `index'th field must satisfy.
  6475.  
  6476.   The `defaulter' field is an expression whose value is either `#f' or
  6477. a procedure of one argument (the parameter-list) which returns a *list*
  6478. of the default value or values as appropriate.  Note that since the
  6479. `defaulter' procedure is called every time a default parameter is
  6480. needed for this column, "sticky" defaults can be implemented using
  6481. shared state with the domain-integrity-rule.
  6482.  
  6483. Invoking Commands
  6484. .................
  6485.  
  6486.   When an enhanced relational-database is called with a symbol which
  6487. matches a NAME in the `*commands*' table, the associated procedure
  6488. expression is evaluated and applied to the enhanced
  6489. relational-database.  A procedure should then be returned which the user
  6490. can invoke on (optional) arguments.
  6491.  
  6492.   The command `*initialize*' is special.  If present in the
  6493. `*commands*' table, `open-database' or `open-database!'  will return
  6494. the value of the `*initialize*' command.  Notice that arbitrary code
  6495. can be run when the `*initialize*' procedure is automatically applied
  6496. to the enhanced relational-database.
  6497.  
  6498.   Note also that if you wish to shadow or hide from the user
  6499. relational-database methods described in *Note Relational Database
  6500. Operations::, this can be done by a dispatch in the closure returned by
  6501. the `*initialize*' expression rather than by entries in the
  6502. `*commands*' table if it is desired that the underlying methods remain
  6503. accessible to code in the `*commands*' table.
  6504.  
  6505.  - Function: make-command-server RDB TABLE-NAME
  6506.      Returns a procedure of 2 arguments, a (symbol) command and a
  6507.      call-back procedure.  When this returned procedure is called, it
  6508.      looks up COMMAND in table TABLE-NAME and calls the call-back
  6509.      procedure with arguments:
  6510.     COMMAND
  6511.           The COMMAND
  6512.  
  6513.     COMMAND-VALUE
  6514.           The result of evaluating the expression in the PROCEDURE
  6515.           field of TABLE-NAME and calling it with RDB.
  6516.  
  6517.     PARAMETER-NAME
  6518.           A list of the "official" name of each parameter.  Corresponds
  6519.           to the `name' field of the COMMAND's parameter-table.
  6520.  
  6521.     POSITIONS
  6522.           A list of the positive integer index of each parameter.
  6523.           Corresponds to the `index' field of the COMMAND's
  6524.           parameter-table.
  6525.  
  6526.     ARITIES
  6527.           A list of the arities of each parameter.  Corresponds to the
  6528.           `arity' field of the COMMAND's parameter-table.  For a
  6529.           description of `arity' see table above.
  6530.  
  6531.     TYPES
  6532.           A list of the type name of each parameter.  Correspnds to the
  6533.           `type-id' field of the contents of the `domain' of the
  6534.           COMMAND's parameter-table.
  6535.  
  6536.     DEFAULTERS
  6537.           A list of the defaulters for each parameter.  Corresponds to
  6538.           the `defaulters' field of the COMMAND's parameter-table.
  6539.  
  6540.     DOMAIN-INTEGRITY-RULES
  6541.           A list of procedures (one for each parameter) which tests
  6542.           whether a value for a parameter is acceptable for that
  6543.           parameter.  The procedure should be called with each datum in
  6544.           the list for `nary' arity parameters.
  6545.  
  6546.     ALIASES
  6547.           A list of lists of `(alias parameter-name)'.  There can be
  6548.           more than one alias per PARAMETER-NAME.
  6549.  
  6550.   For information about parameters, *Note Parameter lists::.  Here is an
  6551. example of setting up a command with arguments and parsing those
  6552. arguments from a `getopt' style argument list (*note Getopt::.).
  6553.  
  6554.      (require 'database-utilities)
  6555.      (require 'fluid-let)
  6556.      (require 'parameters)
  6557.      (require 'getopt)
  6558.      
  6559.      (define my-rdb (create-database #f 'alist-table))
  6560.      
  6561.      (define-tables my-rdb
  6562.        '(foo-params
  6563.          *parameter-columns*
  6564.          *parameter-columns*
  6565.          ((1 single-string single string
  6566.              (lambda (pl) '("str")) #f "single string")
  6567.           (2 nary-symbols nary symbol
  6568.              (lambda (pl) '()) #f "zero or more symbols")
  6569.           (3 nary1-symbols nary1 symbol
  6570.              (lambda (pl) '(symb)) #f "one or more symbols")
  6571.           (4 optional-number optional uint
  6572.              (lambda (pl) '()) #f "zero or one number")
  6573.           (5 flag boolean boolean
  6574.              (lambda (pl) '(#f)) #f "a boolean flag")))
  6575.        '(foo-pnames
  6576.          ((name string))
  6577.          ((parameter-index uint))
  6578.          (("s" 1)
  6579.           ("single-string" 1)
  6580.           ("n" 2)
  6581.           ("nary-symbols" 2)
  6582.           ("N" 3)
  6583.           ("nary1-symbols" 3)
  6584.           ("o" 4)
  6585.           ("optional-number" 4)
  6586.           ("f" 5)
  6587.           ("flag" 5)))
  6588.        '(my-commands
  6589.          ((name symbol))
  6590.          ((parameters parameter-list)
  6591.           (parameter-names parameter-name-translation)
  6592.           (procedure expression)
  6593.           (documentation string))
  6594.          ((foo
  6595.            foo-params
  6596.            foo-pnames
  6597.            (lambda (rdb) (lambda args (print args)))
  6598.            "test command arguments"))))
  6599.      
  6600.      (define (dbutil:serve-command-line rdb command-table
  6601.                                         command argc argv)
  6602.        (set! argv (if (vector? argv) (vector->list argv) argv))
  6603.        ((make-command-server rdb command-table)
  6604.         command
  6605.         (lambda (comname comval options positions
  6606.                          arities types defaulters dirs aliases)
  6607.           (apply comval (getopt->arglist
  6608.                          argc argv options positions
  6609.                          arities types defaulters dirs aliases)))))
  6610.      
  6611.      (define (cmd . opts)
  6612.        (fluid-let ((*optind* 1))
  6613.          (printf "%-34s => "
  6614.                  (call-with-output-string
  6615.                   (lambda (pt) (write (cons 'cmd opts) pt))))
  6616.          (set! opts (cons "cmd" opts))
  6617.          (force-output)
  6618.          (dbutil:serve-command-line
  6619.           my-rdb 'my-commands 'foo (length opts) opts)))
  6620.      
  6621.      (cmd)                              => ("str" () (symb) () #f)
  6622.      (cmd "-f")                         => ("str" () (symb) () #t)
  6623.      (cmd "--flag")                     => ("str" () (symb) () #t)
  6624.      (cmd "-o177")                      => ("str" () (symb) (177) #f)
  6625.      (cmd "-o" "177")                   => ("str" () (symb) (177) #f)
  6626.      (cmd "--optional" "621")           => ("str" () (symb) (621) #f)
  6627.      (cmd "--optional=621")             => ("str" () (symb) (621) #f)
  6628.      (cmd "-s" "speciality")            => ("speciality" () (symb) () #f)
  6629.      (cmd "-sspeciality")               => ("speciality" () (symb) () #f)
  6630.      (cmd "--single" "serendipity")     => ("serendipity" () (symb) () #f)
  6631.      (cmd "--single=serendipity")       => ("serendipity" () (symb) () #f)
  6632.      (cmd "-n" "gravity" "piety")       => ("str" () (piety gravity) () #f)
  6633.      (cmd "-ngravity" "piety")          => ("str" () (piety gravity) () #f)
  6634.      (cmd "--nary" "chastity")          => ("str" () (chastity) () #f)
  6635.      (cmd "--nary=chastity" "")         => ("str" () ( chastity) () #f)
  6636.      (cmd "-N" "calamity")              => ("str" () (calamity) () #f)
  6637.      (cmd "-Ncalamity")                 => ("str" () (calamity) () #f)
  6638.      (cmd "--nary1" "surety")           => ("str" () (surety) () #f)
  6639.      (cmd "--nary1=surety")             => ("str" () (surety) () #f)
  6640.      (cmd "-N" "levity" "fealty")       => ("str" () (fealty levity) () #f)
  6641.      (cmd "-Nlevity" "fealty")          => ("str" () (fealty levity) () #f)
  6642.      (cmd "--nary1" "surety" "brevity") => ("str" () (brevity surety) () #f)
  6643.      (cmd "--nary1=surety" "brevity")   => ("str" () (brevity surety) () #f)
  6644.      (cmd "-?")
  6645.      -|
  6646.      Usage: cmd [OPTION ARGUMENT ...] ...
  6647.      
  6648.        -f, --flag
  6649.        -o, --optional[=]<number>
  6650.        -n, --nary[=]<symbols> ...
  6651.        -N, --nary1[=]<symbols> ...
  6652.        -s, --single[=]<string>
  6653.      
  6654.      ERROR: getopt->parameter-list "unrecognized option" "-?"
  6655.  
  6656.   Some commands are defined in all extended relational-databases.  The
  6657. are called just like *Note Relational Database Operations::.
  6658.  
  6659.  - Function: add-domain DOMAIN-ROW
  6660.      Adds DOMAIN-ROW to the "domains" table if there is no row in the
  6661.      domains table associated with key `(car DOMAIN-ROW)' and returns
  6662.      `#t'.  Otherwise returns `#f'.
  6663.  
  6664.      For the fields and layout of the domain table, *Note Catalog
  6665.      Representation::.  Currently, these fields are
  6666.         * domain-name
  6667.  
  6668.         * foreign-table
  6669.  
  6670.         * domain-integrity-rule
  6671.  
  6672.         * type-id
  6673.  
  6674.         * type-param
  6675.  
  6676.      The following example adds 3 domains to the `build' database.
  6677.      `Optstring' is either a string or `#f'.  `filename' is a string
  6678.      and `build-whats' is a symbol.
  6679.  
  6680.           (for-each (build 'add-domain)
  6681.                     '((optstring #f
  6682.                                  (lambda (x) (or (not x) (string? x)))
  6683.                                  string
  6684.                                  #f)
  6685.                       (filename #f #f string #f)
  6686.                       (build-whats #f #f symbol #f)))
  6687.  
  6688.  - Function: delete-domain DOMAIN-NAME
  6689.      Removes and returns the DOMAIN-NAME row from the "domains" table.
  6690.  
  6691.  - Function: domain-checker DOMAIN
  6692.      Returns a procedure to check an argument for conformance to domain
  6693.      DOMAIN.
  6694.  
  6695. Defining Tables
  6696. ...............
  6697.  
  6698.  - Procedure: define-tables RDB SPEC-0 ...
  6699.      Adds tables as specified in SPEC-0 ... to the open
  6700.      relational-database RDB.  Each SPEC has the form:
  6701.  
  6702.           (<name> <descriptor-name> <descriptor-name> <rows>)
  6703.      or
  6704.           (<name> <primary-key-fields> <other-fields> <rows>)
  6705.  
  6706.      where <name> is the table name, <descriptor-name> is the symbol
  6707.      name of a descriptor table, <primary-key-fields> and
  6708.      <other-fields> describe the primary keys and other fields
  6709.      respectively, and <rows> is a list of data rows to be added to the
  6710.      table.
  6711.  
  6712.      <primary-key-fields> and <other-fields> are lists of field
  6713.      descriptors of the form:
  6714.  
  6715.           (<column-name> <domain>)
  6716.      or
  6717.           (<column-name> <domain> <column-integrity-rule>)
  6718.  
  6719.      where <column-name> is the column name, <domain> is the domain of
  6720.      the column, and <column-integrity-rule> is an expression whose
  6721.      value is a procedure of one argument (which returns `#f' to signal
  6722.      an error).
  6723.  
  6724.      If <domain> is not a defined domain name and it matches the name of
  6725.      this table or an already defined (in one of SPEC-0 ...) single key
  6726.      field table, a foriegn-key domain will be created for it.
  6727.  
  6728. The following example shows a new database with the name of `foo.db'
  6729. being created with tables describing processor families and
  6730. processor/os/compiler combinations.
  6731.  
  6732. The database command `define-tables' is defined to call `define-tables'
  6733. with its arguments.  The database is also configured to print `Welcome'
  6734. when the database is opened.  The database is then closed and reopened.
  6735.  
  6736.      (require 'database-utilities)
  6737.      (define my-rdb (create-database "foo.db" 'alist-table))
  6738.      
  6739.      (define-tables my-rdb
  6740.        '(*commands*
  6741.          ((name symbol))
  6742.          ((parameters parameter-list)
  6743.           (procedure expression)
  6744.           (documentation string))
  6745.          ((define-tables
  6746.            no-parameters
  6747.            no-parameter-names
  6748.            (lambda (rdb) (lambda specs (apply define-tables rdb specs)))
  6749.            "Create or Augment tables from list of specs")
  6750.           (*initialize*
  6751.            no-parameters
  6752.            no-parameter-names
  6753.            (lambda (rdb) (display "Welcome") (newline) rdb)
  6754.            "Print Welcome"))))
  6755.      
  6756.      ((my-rdb 'define-tables)
  6757.       '(processor-family
  6758.         ((family    atom))
  6759.         ((also-ran  processor-family))
  6760.         ((m68000           #f)
  6761.          (m68030           m68000)
  6762.          (i386             8086)
  6763.          (8086             #f)
  6764.          (powerpc          #f)))
  6765.      
  6766.       '(platform
  6767.         ((name      symbol))
  6768.         ((processor processor-family)
  6769.          (os        symbol)
  6770.          (compiler  symbol))
  6771.         ((aix              powerpc aix     -)
  6772.          (amiga-dice-c     m68000  amiga   dice-c)
  6773.          (amiga-aztec      m68000  amiga   aztec)
  6774.          (amiga-sas/c-5.10 m68000  amiga   sas/c)
  6775.          (atari-st-gcc     m68000  atari   gcc)
  6776.          (atari-st-turbo-c m68000  atari   turbo-c)
  6777.          (borland-c-3.1    8086    ms-dos  borland-c)
  6778.          (djgpp            i386    ms-dos  gcc)
  6779.          (linux            i386    linux   gcc)
  6780.          (microsoft-c      8086    ms-dos  microsoft-c)
  6781.          (os/2-emx         i386    os/2    gcc)
  6782.          (turbo-c-2        8086    ms-dos  turbo-c)
  6783.          (watcom-9.0       i386    ms-dos  watcom))))
  6784.      
  6785.      ((my-rdb 'close-database))
  6786.      
  6787.      (set! my-rdb (open-database "foo.db" 'alist-table))
  6788.      -|
  6789.      Welcome
  6790.  
  6791. 
  6792. File: slib.info,  Node: Database Reports,  Next: Database Browser,  Prev: Database Utilities,  Up: Relational Database
  6793.  
  6794. Database Reports
  6795. ----------------
  6796.  
  6797. Code for generating database reports is in `report.scm'.  After writing
  6798. it using `format', I discovered that Common-Lisp `format' is not
  6799. useable for this application because there is no mechanismm for
  6800. truncating fields.  `report.scm' needs to be rewritten using `printf'.
  6801.  
  6802.  - Procedure: create-report RDB DESTINATION REPORT-NAME TABLE
  6803.  - Procedure: create-report RDB DESTINATION REPORT-NAME
  6804.      The symbol REPORT-NAME must be primary key in the table named
  6805.      `*reports*' in the relational database RDB.  DESTINATION is a
  6806.      port, string, or symbol.  If DESTINATION is a:
  6807.  
  6808.     port
  6809.           The table is created as ascii text and written to that port.
  6810.  
  6811.     string
  6812.           The table is created as ascii text and written to the file
  6813.           named by DESTINATION.
  6814.  
  6815.     symbol
  6816.           DESTINATION is the primary key for a row in the table named
  6817.           *printers*.
  6818.  
  6819.      The report is prepared as follows:
  6820.  
  6821.         * `Format' (*note Format::.) is called with the `header' field
  6822.           and the (list of) `column-names' of the table.
  6823.  
  6824.         * `Format' is called with the `reporter' field and (on
  6825.           successive calls) each record in the natural order for the
  6826.           table.  A count is kept of the number of newlines output by
  6827.           format.  When the number of newlines to be output exceeds the
  6828.           number of lines per page, the set of lines will be broken if
  6829.           there are more than `minimum-break' left on this page and the
  6830.           number of lines for this row is larger or equal to twice
  6831.           `minimum-break'.
  6832.  
  6833.         * `Format' is called with the `footer' field and the (list of)
  6834.           `column-names' of the table.  The footer field should not
  6835.           output a newline.
  6836.  
  6837.         * A new page is output.
  6838.  
  6839.         * This entire process repeats until all the rows are output.
  6840.  
  6841.   Each row in the table *reports* has the fields:
  6842.  
  6843. name
  6844.      The report name.
  6845.  
  6846. default-table
  6847.      The table to report on if none is specified.
  6848.  
  6849. header, footer
  6850.      A `format' string.  At the beginning and end of each page
  6851.      respectively, `format' is called with this string and the (list of)
  6852.      column-names of this table.
  6853.  
  6854. reporter
  6855.      A `format' string.  For each row in the table, `format' is called
  6856.      with this string and the row.
  6857.  
  6858. minimum-break
  6859.      The minimum number of lines into which the report lines for a row
  6860.      can be broken.  Use `0' if a row's lines should not be broken over
  6861.      page boundaries.
  6862.  
  6863.   Each row in the table *printers* has the fields:
  6864.  
  6865. name
  6866.      The printer name.
  6867.  
  6868. print-procedure
  6869.      The procedure to call to actually print.
  6870.  
  6871. 
  6872. File: slib.info,  Node: Database Browser,  Prev: Database Reports,  Up: Relational Database
  6873.  
  6874. Database Browser
  6875. ----------------
  6876.  
  6877.   (require 'database-browse)
  6878.  
  6879.  - Procedure: browse DATABASE
  6880.      Prints the names of all the tables in DATABASE and sets browse's
  6881.      default to DATABASE.
  6882.  
  6883.  - Procedure: browse
  6884.      Prints the names of all the tables in the default database.
  6885.  
  6886.  - Procedure: browse TABLE-NAME
  6887.      For each record of the table named by the symbol TABLE-NAME,
  6888.      prints a line composed of all the field values.
  6889.  
  6890.  - Procedure: browse PATHNAME
  6891.      Opens the database named by the string PATHNAME, prints the names
  6892.      of all its tables, and sets browse's default to the database.
  6893.  
  6894.  - Procedure: browse DATABASE TABLE-NAME
  6895.      Sets browse's default to DATABASE and prints the records of the
  6896.      table named by the symbol TABLE-NAME.
  6897.  
  6898.  - Procedure: browse PATHNAME TABLE-NAME
  6899.      Opens the database named by the string PATHNAME and sets browse's
  6900.      default to it; `browse' prints the records of the table named by
  6901.      the symbol TABLE-NAME.
  6902.  
  6903.  
  6904. 
  6905. File: slib.info,  Node: Weight-Balanced Trees,  Prev: Relational Database,  Up: Database Packages
  6906.  
  6907. Weight-Balanced Trees
  6908. =====================
  6909.  
  6910.   `(require 'wt-tree)'
  6911.  
  6912.   Balanced binary trees are a useful data structure for maintaining
  6913. large sets of ordered objects or sets of associations whose keys are
  6914. ordered.  MIT Scheme has an comprehensive implementation of
  6915. weight-balanced binary trees which has several advantages over the
  6916. other data structures for large aggregates:
  6917.  
  6918.    * In addition to the usual element-level operations like insertion,
  6919.      deletion and lookup, there is a full complement of collection-level
  6920.      operations, like set intersection, set union and subset test, all
  6921.      of which are implemented with good orders of growth in time and
  6922.      space.  This makes weight balanced trees ideal for rapid
  6923.      prototyping of functionally derived specifications.
  6924.  
  6925.    * An element in a tree may be indexed by its position under the
  6926.      ordering of the keys, and the ordinal position of an element may
  6927.      be determined, both with reasonable efficiency.
  6928.  
  6929.    * Operations to find and remove minimum element make weight balanced
  6930.      trees simple to use for priority queues.
  6931.  
  6932.    * The implementation is *functional* rather than *imperative*.  This
  6933.      means that operations like `inserting' an association in a tree do
  6934.      not destroy the old tree, in much the same way that `(+ 1 x)'
  6935.      modifies neither the constant 1 nor the value bound to `x'.  The
  6936.      trees are referentially transparent thus the programmer need not
  6937.      worry about copying the trees.  Referential transparency allows
  6938.      space efficiency to be achieved by sharing subtrees.
  6939.  
  6940.   These features make weight-balanced trees suitable for a wide range of
  6941. applications, especially those that require large numbers of sets or
  6942. discrete maps.  Applications that have a few global databases and/or
  6943. concentrate on element-level operations like insertion and lookup are
  6944. probably better off using hash-tables or red-black trees.
  6945.  
  6946.   The *size* of a tree is the number of associations that it contains.
  6947. Weight balanced binary trees are balanced to keep the sizes of the
  6948. subtrees of each node within a constant factor of each other.  This
  6949. ensures logarithmic times for single-path operations (like lookup and
  6950. insertion).  A weight balanced tree takes space that is proportional to
  6951. the number of associations in the tree.  For the current
  6952. implementation, the constant of proportionality is six words per
  6953. association.
  6954.  
  6955.   Weight balanced trees can be used as an implementation for either
  6956. discrete sets or discrete maps (associations).  Sets are implemented by
  6957. ignoring the datum that is associated with the key.  Under this scheme
  6958. if an associations exists in the tree this indicates that the key of the
  6959. association is a member of the set.  Typically a value such as `()',
  6960. `#t' or `#f' is associated with the key.
  6961.  
  6962.   Many operations can be viewed as computing a result that, depending on
  6963. whether the tree arguments are thought of as sets or maps, is known by
  6964. two different names.  An example is `wt-tree/member?', which, when
  6965. regarding the tree argument as a set, computes the set membership
  6966. operation, but, when regarding the tree as a discrete map,
  6967. `wt-tree/member?' is the predicate testing if the map is defined at an
  6968. element in its domain.  Most names in this package have been chosen
  6969. based on interpreting the trees as sets, hence the name
  6970. `wt-tree/member?' rather than `wt-tree/defined-at?'.
  6971.  
  6972.   The weight balanced tree implementation is a run-time-loadable option.
  6973. To use weight balanced trees, execute
  6974.  
  6975.      (load-option 'wt-tree)
  6976.  
  6977. once before calling any of the procedures defined here.
  6978.  
  6979. * Menu:
  6980.  
  6981. * Construction of Weight-Balanced Trees::
  6982. * Basic Operations on Weight-Balanced Trees::
  6983. * Advanced Operations on Weight-Balanced Trees::
  6984. * Indexing Operations on Weight-Balanced Trees::
  6985.  
  6986. 
  6987. File: slib.info,  Node: Construction of Weight-Balanced Trees,  Next: Basic Operations on Weight-Balanced Trees,  Prev: Weight-Balanced Trees,  Up: Weight-Balanced Trees
  6988.  
  6989. Construction of Weight-Balanced Trees
  6990. -------------------------------------
  6991.  
  6992.   Binary trees require there to be a total order on the keys used to
  6993. arrange the elements in the tree.  Weight balanced trees are organized
  6994. by *types*, where the type is an object encapsulating the ordering
  6995. relation.  Creating a tree is a two-stage process.  First a tree type
  6996. must be created from the predicate which gives the ordering.  The tree
  6997. type is then used for making trees, either empty or singleton trees or
  6998. trees from other aggregate structures like association lists.  Once
  6999. created, a tree `knows' its type and the type is used to test
  7000. compatibility between trees in operations taking two trees.  Usually a
  7001. small number of tree types are created at the beginning of a program and
  7002. used many times throughout the program's execution.
  7003.  
  7004.  - procedure+: make-wt-tree-type KEY<?
  7005.      This procedure creates and returns a new tree type based on the
  7006.      ordering predicate KEY<?.  KEY<? must be a total ordering, having
  7007.      the property that for all key values `a', `b' and `c':
  7008.  
  7009.           (key<? a a)                         => #f
  7010.           (and (key<? a b) (key<? b a))       => #f
  7011.           (if (and (key<? a b) (key<? b c))
  7012.               (key<? a c)
  7013.               #t)                             => #t
  7014.  
  7015.      Two key values are assumed to be equal if neither is less than the
  7016.      other by KEY<?.
  7017.  
  7018.      Each call to `make-wt-tree-type' returns a distinct value, and
  7019.      trees are only compatible if their tree types are `eq?'.  A
  7020.      consequence is that trees that are intended to be used in binary
  7021.      tree operations must all be created with a tree type originating
  7022.      from the same call to `make-wt-tree-type'.
  7023.  
  7024.  - variable+: number-wt-type
  7025.      A standard tree type for trees with numeric keys.  `Number-wt-type'
  7026.      could have been defined by
  7027.  
  7028.           (define number-wt-type (make-wt-tree-type  <))
  7029.  
  7030.  - variable+: string-wt-type
  7031.      A standard tree type for trees with string keys.  `String-wt-type'
  7032.      could have been defined by
  7033.  
  7034.           (define string-wt-type (make-wt-tree-type  string<?))
  7035.  
  7036.  - procedure+: make-wt-tree WT-TREE-TYPE
  7037.      This procedure creates and returns a newly allocated weight
  7038.      balanced tree.  The tree is empty, i.e. it contains no
  7039.      associations.  WT-TREE-TYPE is a weight balanced tree type
  7040.      obtained by calling `make-wt-tree-type'; the returned tree has
  7041.      this type.
  7042.  
  7043.  - procedure+: singleton-wt-tree WT-TREE-TYPE KEY DATUM
  7044.      This procedure creates and returns a newly allocated weight
  7045.      balanced tree.  The tree contains a single association, that of
  7046.      DATUM with KEY.  WT-TREE-TYPE is a weight balanced tree type
  7047.      obtained by calling `make-wt-tree-type'; the returned tree has
  7048.      this type.
  7049.  
  7050.  - procedure+: alist->wt-tree TREE-TYPE ALIST
  7051.      Returns a newly allocated weight-balanced tree that contains the
  7052.      same associations as ALIST.  This procedure is equivalent to:
  7053.  
  7054.           (lambda (type alist)
  7055.             (let ((tree (make-wt-tree type)))
  7056.               (for-each (lambda (association)
  7057.                           (wt-tree/add! tree
  7058.                                         (car association)
  7059.                                         (cdr association)))
  7060.                         alist)
  7061.               tree))
  7062.  
  7063. 
  7064. File: slib.info,  Node: Basic Operations on Weight-Balanced Trees,  Next: Advanced Operations on Weight-Balanced Trees,  Prev: Construction of Weight-Balanced Trees,  Up: Weight-Balanced Trees
  7065.  
  7066. Basic Operations on Weight-Balanced Trees
  7067. -----------------------------------------
  7068.  
  7069.   This section describes the basic tree operations on weight balanced
  7070. trees.  These operations are the usual tree operations for insertion,
  7071. deletion and lookup, some predicates and a procedure for determining the
  7072. number of associations in a tree.
  7073.  
  7074.  - procedure+: wt-tree? OBJECT
  7075.      Returns `#t' if OBJECT is a weight-balanced tree, otherwise
  7076.      returns `#f'.
  7077.  
  7078.  - procedure+: wt-tree/empty? WT-TREE
  7079.      Returns `#t' if WT-TREE contains no associations, otherwise
  7080.      returns `#f'.
  7081.  
  7082.  - procedure+: wt-tree/size WT-TREE
  7083.      Returns the number of associations in WT-TREE, an exact
  7084.      non-negative integer.  This operation takes constant time.
  7085.  
  7086.  - procedure+: wt-tree/add WT-TREE KEY DATUM
  7087.      Returns a new tree containing all the associations in WT-TREE and
  7088.      the association of DATUM with KEY.  If WT-TREE already had an
  7089.      association for KEY, the new association overrides the old.  The
  7090.      average and worst-case times required by this operation are
  7091.      proportional to the logarithm of the number of associations in
  7092.      WT-TREE.
  7093.  
  7094.  - procedure+: wt-tree/add! WT-TREE KEY DATUM
  7095.      Associates DATUM with KEY in WT-TREE and returns an unspecified
  7096.      value.  If WT-TREE already has an association for KEY, that
  7097.      association is replaced.  The average and worst-case times
  7098.      required by this operation are proportional to the logarithm of
  7099.      the number of associations in WT-TREE.
  7100.  
  7101.  - procedure+: wt-tree/member? KEY WT-TREE
  7102.      Returns `#t' if WT-TREE contains an association for KEY, otherwise
  7103.      returns `#f'.  The average and worst-case times required by this
  7104.      operation are proportional to the logarithm of the number of
  7105.      associations in WT-TREE.
  7106.  
  7107.  - procedure+: wt-tree/lookup WT-TREE KEY DEFAULT
  7108.      Returns the datum associated with KEY in WT-TREE.  If WT-TREE
  7109.      doesn't contain an association for KEY, DEFAULT is returned.  The
  7110.      average and worst-case times required by this operation are
  7111.      proportional to the logarithm of the number of associations in
  7112.      WT-TREE.
  7113.  
  7114.  - procedure+: wt-tree/delete WT-TREE KEY
  7115.      Returns a new tree containing all the associations in WT-TREE,
  7116.      except that if WT-TREE contains an association for KEY, it is
  7117.      removed from the result.  The average and worst-case times required
  7118.      by this operation are proportional to the logarithm of the number
  7119.      of associations in WT-TREE.
  7120.  
  7121.  - procedure+: wt-tree/delete! WT-TREE KEY
  7122.      If WT-TREE contains an association for KEY the association is
  7123.      removed.  Returns an unspecified value.  The average and worst-case
  7124.      times required by this operation are proportional to the logarithm
  7125.      of the number of associations in WT-TREE.
  7126.  
  7127. 
  7128. File: slib.info,  Node: Advanced Operations on Weight-Balanced Trees,  Next: Indexing Operations on Weight-Balanced Trees,  Prev: Basic Operations on Weight-Balanced Trees,  Up: Weight-Balanced Trees
  7129.  
  7130. Advanced Operations on Weight-Balanced Trees
  7131. --------------------------------------------
  7132.  
  7133.   In the following the *size* of a tree is the number of associations
  7134. that the tree contains, and a *smaller* tree contains fewer
  7135. associations.
  7136.  
  7137.  - procedure+: wt-tree/split< WT-TREE BOUND
  7138.      Returns a new tree containing all and only the associations in
  7139.      WT-TREE which have a key that is less than BOUND in the ordering
  7140.      relation of the tree type of WT-TREE.  The average and worst-case
  7141.      times required by this operation are proportional to the logarithm
  7142.      of the size of WT-TREE.
  7143.  
  7144.  - procedure+: wt-tree/split> WT-TREE BOUND
  7145.      Returns a new tree containing all and only the associations in
  7146.      WT-TREE which have a key that is greater than BOUND in the
  7147.      ordering relation of the tree type of WT-TREE.  The average and
  7148.      worst-case times required by this operation are proportional to the
  7149.      logarithm of size of WT-TREE.
  7150.  
  7151.  - procedure+: wt-tree/union WT-TREE-1 WT-TREE-2
  7152.      Returns a new tree containing all the associations from both trees.
  7153.      This operation is asymmetric: when both trees have an association
  7154.      for the same key, the returned tree associates the datum from
  7155.      WT-TREE-2 with the key.  Thus if the trees are viewed as discrete
  7156.      maps then `wt-tree/union' computes the map override of WT-TREE-1 by
  7157.      WT-TREE-2.  If the trees are viewed as sets the result is the set
  7158.      union of the arguments.  The worst-case time required by this
  7159.      operation is proportional to the sum of the sizes of both trees.
  7160.      If the minimum key of one tree is greater than the maximum key of
  7161.      the other tree then the time required is at worst proportional to
  7162.      the logarithm of the size of the larger tree.
  7163.  
  7164.  - procedure+: wt-tree/intersection WT-TREE-1 WT-TREE-2
  7165.      Returns a new tree containing all and only those associations from
  7166.      WT-TREE-1 which have keys appearing as the key of an association
  7167.      in WT-TREE-2.  Thus the associated data in the result are those
  7168.      from WT-TREE-1.  If the trees are being used as sets the result is
  7169.      the set intersection of the arguments.  As a discrete map
  7170.      operation, `wt-tree/intersection' computes the domain restriction
  7171.      of WT-TREE-1 to (the domain of) WT-TREE-2.  The time required by
  7172.      this operation is never worse that proportional to the sum of the
  7173.      sizes of the trees.
  7174.  
  7175.  - procedure+: wt-tree/difference WT-TREE-1 WT-TREE-2
  7176.      Returns a new tree containing all and only those associations from
  7177.      WT-TREE-1 which have keys that *do not* appear as the key of an
  7178.      association in WT-TREE-2.  If the trees are viewed as sets the
  7179.      result is the asymmetric set difference of the arguments.  As a
  7180.      discrete map operation, it computes the domain restriction of
  7181.      WT-TREE-1 to the complement of (the domain of) WT-TREE-2.  The
  7182.      time required by this operation is never worse that proportional to
  7183.      the sum of the sizes of the trees.
  7184.  
  7185.  - procedure+: wt-tree/subset? WT-TREE-1 WT-TREE-2
  7186.      Returns `#t' iff the key of each association in WT-TREE-1 is the
  7187.      key of some association in WT-TREE-2, otherwise returns `#f'.
  7188.      Viewed as a set operation, `wt-tree/subset?' is the improper subset
  7189.      predicate.  A proper subset predicate can be constructed:
  7190.  
  7191.           (define (proper-subset? s1 s2)
  7192.             (and (wt-tree/subset? s1 s2)
  7193.                  (< (wt-tree/size s1) (wt-tree/size s2))))
  7194.  
  7195.      As a discrete map operation, `wt-tree/subset?' is the subset test
  7196.      on the domain(s) of the map(s).  In the worst-case the time
  7197.      required by this operation is proportional to the size of
  7198.      WT-TREE-1.
  7199.  
  7200.  - procedure+: wt-tree/set-equal? WT-TREE-1 WT-TREE-2
  7201.      Returns `#t' iff for every association in WT-TREE-1 there is an
  7202.      association in WT-TREE-2 that has the same key, and *vice versa*.
  7203.  
  7204.      Viewing the arguments as sets `wt-tree/set-equal?' is the set
  7205.      equality predicate.  As a map operation it determines if two maps
  7206.      are defined on the same domain.
  7207.  
  7208.      This procedure is equivalent to
  7209.  
  7210.           (lambda (wt-tree-1 wt-tree-2)
  7211.             (and (wt-tree/subset? wt-tree-1 wt-tree-2
  7212.                  (wt-tree/subset? wt-tree-2 wt-tree-1)))
  7213.  
  7214.      In the worst-case the time required by this operation is
  7215.      proportional to the size of the smaller tree.
  7216.  
  7217.  - procedure+: wt-tree/fold COMBINER INITIAL WT-TREE
  7218.      This procedure reduces WT-TREE by combining all the associations,
  7219.      using an reverse in-order traversal, so the associations are
  7220.      visited in reverse order.  COMBINER is a procedure of three
  7221.      arguments: a key, a datum and the accumulated result so far.
  7222.      Provided COMBINER takes time bounded by a constant, `wt-tree/fold'
  7223.      takes time proportional to the size of WT-TREE.
  7224.  
  7225.      A sorted association list can be derived simply:
  7226.  
  7227.           (wt-tree/fold  (lambda (key datum list)
  7228.                            (cons (cons key datum) list))
  7229.                          '()
  7230.                          WT-TREE))
  7231.  
  7232.      The data in the associations can be summed like this:
  7233.  
  7234.           (wt-tree/fold  (lambda (key datum sum) (+ sum datum))
  7235.                          0
  7236.                          WT-TREE)
  7237.  
  7238.  - procedure+: wt-tree/for-each ACTION WT-TREE
  7239.      This procedure traverses the tree in-order, applying ACTION to
  7240.      each association.  The associations are processed in increasing
  7241.      order of their keys.  ACTION is a procedure of two arguments which
  7242.      take the key and datum respectively of the association.  Provided
  7243.      ACTION takes time bounded by a constant, `wt-tree/for-each' takes
  7244.      time proportional to in the size of WT-TREE.  The example prints
  7245.      the tree:
  7246.  
  7247.           (wt-tree/for-each (lambda (key value)
  7248.                               (display (list key value)))
  7249.                             WT-TREE))
  7250.  
  7251. 
  7252. File: slib.info,  Node: Indexing Operations on Weight-Balanced Trees,  Prev: Advanced Operations on Weight-Balanced Trees,  Up: Weight-Balanced Trees
  7253.  
  7254. Indexing Operations on Weight-Balanced Trees
  7255. --------------------------------------------
  7256.  
  7257.   Weight balanced trees support operations that view the tree as sorted
  7258. sequence of associations.  Elements of the sequence can be accessed by
  7259. position, and the position of an element in the sequence can be
  7260. determined, both in logarthmic time.
  7261.  
  7262.  - procedure+: wt-tree/index WT-TREE INDEX
  7263.  - procedure+: wt-tree/index-datum WT-TREE INDEX
  7264.  - procedure+: wt-tree/index-pair WT-TREE INDEX
  7265.      Returns the 0-based INDEXth association of WT-TREE in the sorted
  7266.      sequence under the tree's ordering relation on the keys.
  7267.      `wt-tree/index' returns the INDEXth key, `wt-tree/index-datum'
  7268.      returns the datum associated with the INDEXth key and
  7269.      `wt-tree/index-pair' returns a new pair `(KEY . DATUM)' which is
  7270.      the `cons' of the INDEXth key and its datum.  The average and
  7271.      worst-case times required by this operation are proportional to
  7272.      the logarithm of the number of associations in the tree.
  7273.  
  7274.      These operations signal an error if the tree is empty, if
  7275.      INDEX`<0', or if INDEX is greater than or equal to the number of
  7276.      associations in the tree.
  7277.  
  7278.      Indexing can be used to find the median and maximum keys in the
  7279.      tree as follows:
  7280.  
  7281.           median:   (wt-tree/index WT-TREE
  7282.                                    (quotient (wt-tree/size WT-TREE) 2))
  7283.           
  7284.           maximum:  (wt-tree/index WT-TREE
  7285.                                    (-1+ (wt-tree/size WT-TREE)))
  7286.  
  7287.  - procedure+: wt-tree/rank WT-TREE KEY
  7288.      Determines the 0-based position of KEY in the sorted sequence of
  7289.      the keys under the tree's ordering relation, or `#f' if the tree
  7290.      has no association with for KEY.  This procedure returns either an
  7291.      exact non-negative integer or `#f'.  The average and worst-case
  7292.      times required by this operation are proportional to the logarithm
  7293.      of the number of associations in the tree.
  7294.  
  7295.  - procedure+: wt-tree/min WT-TREE
  7296.  - procedure+: wt-tree/min-datum WT-TREE
  7297.  - procedure+: wt-tree/min-pair WT-TREE
  7298.      Returns the association of WT-TREE that has the least key under
  7299.      the tree's ordering relation.  `wt-tree/min' returns the least key,
  7300.      `wt-tree/min-datum' returns the datum associated with the least key
  7301.      and `wt-tree/min-pair' returns a new pair `(key . datum)' which is
  7302.      the `cons' of the minimum key and its datum.  The average and
  7303.      worst-case times required by this operation are proportional to the
  7304.      logarithm of the number of associations in the tree.
  7305.  
  7306.      These operations signal an error if the tree is empty.  They could
  7307.      be written
  7308.           (define (wt-tree/min tree)        (wt-tree/index tree 0))
  7309.           (define (wt-tree/min-datum tree)  (wt-tree/index-datum tree 0))
  7310.           (define (wt-tree/min-pair tree)   (wt-tree/index-pair tree 0))
  7311.  
  7312.  - procedure+: wt-tree/delete-min WT-TREE
  7313.      Returns a new tree containing all of the associations in WT-TREE
  7314.      except the association with the least key under the WT-TREE's
  7315.      ordering relation.  An error is signalled if the tree is empty.
  7316.      The average and worst-case times required by this operation are
  7317.      proportional to the logarithm of the number of associations in the
  7318.      tree.  This operation is equivalent to
  7319.  
  7320.           (wt-tree/delete WT-TREE (wt-tree/min WT-TREE))
  7321.  
  7322.  - procedure+: wt-tree/delete-min! WT-TREE
  7323.      Removes the association with the least key under the WT-TREE's
  7324.      ordering relation.  An error is signalled if the tree is empty.
  7325.      The average and worst-case times required by this operation are
  7326.      proportional to the logarithm of the number of associations in the
  7327.      tree.  This operation is equivalent to
  7328.  
  7329.           (wt-tree/delete! WT-TREE (wt-tree/min WT-TREE))
  7330.  
  7331. 
  7332. File: slib.info,  Node: Other Packages,  Next: About SLIB,  Prev: Database Packages,  Up: Top
  7333.  
  7334. Other Packages
  7335. **************
  7336.  
  7337. * Menu:
  7338.  
  7339. * Data Structures::             Various data structures.
  7340. * Procedures::                  Miscellaneous utility procedures.
  7341. * Standards Support::           Support for Scheme Standards.
  7342. * Session Support::             REPL and Debugging.
  7343. * Extra-SLIB Packages::
  7344.  
  7345. 
  7346. File: slib.info,  Node: Data Structures,  Next: Procedures,  Prev: Other Packages,  Up: Other Packages
  7347.  
  7348. Data Structures
  7349. ===============
  7350.  
  7351. * Menu:
  7352.  
  7353. * Arrays::                      'array
  7354. * Array Mapping::               'array-for-each
  7355. * Association Lists::           'alist
  7356. * Byte::                        'byte
  7357. * Collections::                 'collect
  7358. * Dynamic Data Type::           'dynamic
  7359. * Hash Tables::                 'hash-table
  7360. * Hashing::                     'hash, 'sierpinski, 'soundex
  7361. * Object::                      'object
  7362. * Priority Queues::             'priority-queue
  7363. * Queues::                      'queue
  7364. * Records::                     'record
  7365. * Structures::                  'struct, 'structure
  7366.  
  7367. 
  7368. File: slib.info,  Node: Arrays,  Next: Array Mapping,  Prev: Data Structures,  Up: Data Structures
  7369.  
  7370. Arrays
  7371. ------
  7372.  
  7373.   `(require 'array)'
  7374.  
  7375.  - Function: array? OBJ
  7376.      Returns `#t' if the OBJ is an array, and `#f' if not.
  7377.  
  7378.  - Function: make-array INITIAL-VALUE BOUND1 BOUND2 ...
  7379.      Creates and returns an array that has as many dimensins as there
  7380.      are BOUNDs and fills it with INITIAL-VALUE.
  7381.  
  7382.   When constructing an array, BOUND is either an inclusive range of
  7383. indices expressed as a two element list, or an upper bound expressed as
  7384. a single integer.  So
  7385.      (make-array 'foo 3 3) == (make-array 'foo '(0 2) '(0 2))
  7386.  
  7387.  - Function: make-shared-array ARRAY MAPPER BOUND1 BOUND2 ...
  7388.      `make-shared-array' can be used to create shared subarrays of other
  7389.      arrays.  The MAPPER is a function that translates coordinates in
  7390.      the new array into coordinates in the old array.  A MAPPER must be
  7391.      linear, and its range must stay within the bounds of the old
  7392.      array, but it can be otherwise arbitrary.  A simple example:
  7393.           (define fred (make-array #f 8 8))
  7394.           (define freds-diagonal
  7395.             (make-shared-array fred (lambda (i) (list i i)) 8))
  7396.           (array-set! freds-diagonal 'foo 3)
  7397.           (array-ref fred 3 3)
  7398.              => FOO
  7399.           (define freds-center
  7400.             (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
  7401.                                2 2))
  7402.           (array-ref freds-center 0 0)
  7403.              => FOO
  7404.  
  7405.  - Function: array-rank OBJ
  7406.      Returns the number of dimensions of OBJ.  If OBJ is not an array,
  7407.      0 is returned.
  7408.  
  7409.  - Function: array-shape ARRAY
  7410.      `array-shape' returns a list of inclusive bounds.  So:
  7411.           (array-shape (make-array 'foo 3 5))
  7412.              => ((0 2) (0 4))
  7413.  
  7414.  - Function: array-dimensions ARRAY
  7415.      `array-dimensions' is similar to `array-shape' but replaces
  7416.      elements with a 0 minimum with one greater than the maximum. So:
  7417.           (array-dimensions (make-array 'foo 3 5))
  7418.              => (3 5)
  7419.  
  7420.  - Procedure: array-in-bounds? ARRAY INDEX1 INDEX2 ...
  7421.      Returns `#t' if its arguments would be acceptable to `array-ref'.
  7422.  
  7423.  - Function: array-ref ARRAY INDEX1 INDEX2 ...
  7424.      Returns the element at the `(INDEX1, INDEX2)' element in ARRAY.
  7425.  
  7426.  - Procedure: array-set! ARRAY NEW-VALUE INDEX1 INDEX2 ...
  7427.  
  7428.  - Function: array-1d-ref ARRAY INDEX
  7429.  - Function: array-2d-ref ARRAY INDEX1 INDEX2
  7430.  - Function: array-3d-ref ARRAY INDEX1 INDEX2 INDEX3
  7431.  
  7432.  - Procedure: array-1d-set! ARRAY NEW-VALUE INDEX
  7433.  - Procedure: array-2d-set! ARRAY NEW-VALUE INDEX1 INDEX2
  7434.  - Procedure: array-3d-set! ARRAY NEW-VALUE INDEX1 INDEX2 INDEX3
  7435.  
  7436.   The functions are just fast versions of `array-ref' and `array-set!'
  7437. that take a fixed number of arguments, and perform no bounds checking.
  7438.  
  7439.   If you comment out the bounds checking code, this is about as
  7440. efficient as you could ask for without help from the compiler.
  7441.  
  7442.   An exercise left to the reader: implement the rest of APL.
  7443.  
  7444. 
  7445. File: slib.info,  Node: Array Mapping,  Next: Association Lists,  Prev: Arrays,  Up: Data Structures
  7446.  
  7447. Array Mapping
  7448. -------------
  7449.  
  7450.   `(require 'array-for-each)'
  7451.  
  7452.  - Function: array-map! ARRAY0 PROC ARRAY1 ...
  7453.      ARRAY1, ... must have the same number of dimensions as ARRAY0 and
  7454.      have a range for each index which includes the range for the
  7455.      corresponding index in ARRAY0.  PROC is applied to each tuple of
  7456.      elements of ARRAY1 ... and the result is stored as the
  7457.      corresponding element in ARRAY0.  The value returned is
  7458.      unspecified.  The order of application is unspecified.
  7459.  
  7460.  - Function: array-for-each PROC ARRAY0 ...
  7461.      PROC is applied to each tuple of elements of ARRAY0 ...  in
  7462.      row-major order.  The value returned is unspecified.
  7463.  
  7464.  - Function: array-indexes ARRAY
  7465.      Returns an array of lists of indexes for ARRAY such that, if LI is
  7466.      a list of indexes for which ARRAY is defined, (equal?  LI (apply
  7467.      array-ref (array-indexes ARRAY) LI)).
  7468.  
  7469.  - Function: array-index-map! ARRAY PROC
  7470.      applies PROC to the indices of each element of ARRAY in turn,
  7471.      storing the result in the corresponding element.  The value
  7472.      returned and the order of application are unspecified.
  7473.  
  7474.      One can implement ARRAY-INDEXES as
  7475.           (define (array-indexes array)
  7476.               (let ((ra (apply make-array #f (array-shape array))))
  7477.                 (array-index-map! ra (lambda x x))
  7478.                 ra))
  7479.      Another example:
  7480.           (define (apl:index-generator n)
  7481.               (let ((v (make-uniform-vector n 1)))
  7482.                 (array-index-map! v (lambda (i) i))
  7483.                 v))
  7484.  
  7485.  - Function: array-copy! SOURCE DESTINATION
  7486.      Copies every element from vector or array SOURCE to the
  7487.      corresponding element of DESTINATION.  DESTINATION must have the
  7488.      same rank as SOURCE, and be at least as large in each dimension.
  7489.      The order of copying is unspecified.
  7490.  
  7491. 
  7492. File: slib.info,  Node: Association Lists,  Next: Byte,  Prev: Array Mapping,  Up: Data Structures
  7493.  
  7494. Association Lists
  7495. -----------------
  7496.  
  7497.   `(require 'alist)'
  7498.  
  7499.   Alist functions provide utilities for treating a list of key-value
  7500. pairs as an associative database.  These functions take an equality
  7501. predicate, PRED, as an argument.  This predicate should be repeatable,
  7502. symmetric, and transitive.
  7503.  
  7504.   Alist functions can be used with a secondary index method such as hash
  7505. tables for improved performance.
  7506.  
  7507.  - Function: predicate->asso PRED
  7508.      Returns an "association function" (like `assq', `assv', or
  7509.      `assoc') corresponding to PRED.  The returned function returns a
  7510.      key-value pair whose key is `pred'-equal to its first argument or
  7511.      `#f' if no key in the alist is PRED-equal to the first argument.
  7512.  
  7513.  - Function: alist-inquirer PRED
  7514.      Returns a procedure of 2 arguments, ALIST and KEY, which returns
  7515.      the value associated with KEY in ALIST or `#f' if KEY does not
  7516.      appear in ALIST.
  7517.  
  7518.  - Function: alist-associator PRED
  7519.      Returns a procedure of 3 arguments, ALIST, KEY, and VALUE, which
  7520.      returns an alist with KEY and VALUE associated.  Any previous
  7521.      value associated with KEY will be lost.  This returned procedure
  7522.      may or may not have side effects on its ALIST argument.  An
  7523.      example of correct usage is:
  7524.           (define put (alist-associator string-ci=?))
  7525.           (define alist '())
  7526.           (set! alist (put alist "Foo" 9))
  7527.  
  7528.  - Function: alist-remover PRED
  7529.      Returns a procedure of 2 arguments, ALIST and KEY, which returns
  7530.      an alist with an association whose KEY is key removed.  This
  7531.      returned procedure may or may not have side effects on its ALIST
  7532.      argument.  An example of correct usage is:
  7533.           (define rem (alist-remover string-ci=?))
  7534.           (set! alist (rem alist "foo"))
  7535.  
  7536.  - Function: alist-map PROC ALIST
  7537.      Returns a new association list formed by mapping PROC over the
  7538.      keys and values of ALIST.   PROC must be a function of 2 arguments
  7539.      which returns the new value part.
  7540.  
  7541.  - Function: alist-for-each PROC ALIST
  7542.      Applies PROC to each pair of keys and values of ALIST.  PROC must
  7543.      be a function of 2 arguments.  The returned value is unspecified.
  7544.  
  7545. 
  7546. File: slib.info,  Node: Byte,  Next: Collections,  Prev: Association Lists,  Up: Data Structures
  7547.  
  7548. Byte
  7549. ----
  7550.  
  7551.   `(require 'byte)'
  7552.  
  7553.   Some algorithms are expressed in terms of arrays of small integers.
  7554. Using Scheme strings to implement these arrays is not portable vis-a-vis
  7555. the correspondence between integers and characters and non-ascii
  7556. character sets.  These functions abstract the notion of a "byte".
  7557.  
  7558.  - Function: byte-ref BYTES K
  7559.      K must be a valid index of BYTES.  `byte-ref' returns byte K of
  7560.      BYTES using zero-origin indexing.
  7561.  
  7562.  - Procedure: byte-set! BYTES K BYTE
  7563.      K must be a valid index of BYTES%, and BYTE must be a small
  7564.      integer.  `Byte-set!' stores BYTE in element K of BYTES and
  7565.      returns an unspecified value.
  7566.  
  7567.  - Function: make-bytes K
  7568.  - Function: make-bytes K BYTE
  7569.      `Make-bytes' returns a newly allocated byte-array of length K.  If
  7570.      BYTE is given, then all elements of the byte-array are initialized
  7571.      to BYTE, otherwise the contents of the byte-array are unspecified.
  7572.  
  7573.  
  7574.  - Function: bytes-length BYTES
  7575.      `bytes-length' returns length of byte-array BYTES.
  7576.  
  7577.  
  7578.  - Function: write-byte BYTE
  7579.  - Function: write-byte BYTE PORT
  7580.      Writes the byte BYTE (not an external representation of the byte)
  7581.      to the given PORT and returns an unspecified value.  The PORT
  7582.      argument may be omitted, in which case it defaults to the value
  7583.      returned by `current-output-port'.
  7584.  
  7585.  
  7586.  - Function: read-byte
  7587.  - Function: read-byte PORT
  7588.      Returns the next byte available from the input PORT, updating the
  7589.      PORT to point to the following byte.  If no more bytes are
  7590.      available, an end of file object is returned.  PORT may be
  7591.      omitted, in which case it defaults to the value returned by
  7592.      `current-input-port'.
  7593.  
  7594.  
  7595.  - Function: bytes BYTE ...
  7596.      Returns a newly allocated byte-array composed of the arguments.
  7597.  
  7598.  
  7599.  - Function: bytes->list BYTES
  7600.  - Function: list->bytes BYTES
  7601.      `Bytes->list' returns a newly allocated list of the bytes that
  7602.      make up the given byte-array.  `List->bytes' returns a newly
  7603.      allocated byte-array formed from the small integers in the list
  7604.      BYTES. `Bytes->list' and `list->bytes' are inverses so far as
  7605.      `equal?' is concerned.
  7606.  
  7607.  
  7608. 
  7609. File: slib.info,  Node: Collections,  Next: Dynamic Data Type,  Prev: Byte,  Up: Data Structures
  7610.  
  7611. Collections
  7612. -----------
  7613.  
  7614.   `(require 'collect)'
  7615.  
  7616.   Routines for managing collections.  Collections are aggregate data
  7617. structures supporting iteration over their elements, similar to the
  7618. Dylan(TM) language, but with a different interface.  They have
  7619. "elements" indexed by corresponding "keys", although the keys may be
  7620. implicit (as with lists).
  7621.  
  7622.   New types of collections may be defined as YASOS objects (*note
  7623. Yasos::.).  They must support the following operations:
  7624.    * `(collection? SELF)' (always returns `#t');
  7625.  
  7626.    * `(size SELF)' returns the number of elements in the collection;
  7627.  
  7628.    * `(print SELF PORT)' is a specialized print operation for the
  7629.      collection which prints a suitable representation on the given
  7630.      PORT or returns it as a string if PORT is `#t';
  7631.  
  7632.    * `(gen-elts SELF)' returns a thunk which on successive invocations
  7633.      yields elements of SELF in order or gives an error if it is
  7634.      invoked more than `(size SELF)' times;
  7635.  
  7636.    * `(gen-keys SELF)' is like `gen-elts', but yields the collection's
  7637.      keys in order.
  7638.  
  7639.   They might support specialized `for-each-key' and `for-each-elt'
  7640. operations.
  7641.  
  7642.  - Function: collection? OBJ
  7643.      A predicate, true initially of lists, vectors and strings.  New
  7644.      sorts of collections must answer `#t' to `collection?'.
  7645.  
  7646.  - Procedure: map-elts PROC . COLLECTIONS
  7647.  - Procedure: do-elts PROC . COLLECTIONS
  7648.      PROC is a procedure taking as many arguments as there are
  7649.      COLLECTIONS (at least one).  The COLLECTIONS are iterated over in
  7650.      their natural order and PROC is applied to the elements yielded by
  7651.      each iteration in turn.  The order in which the arguments are
  7652.      supplied corresponds to te order in which the COLLECTIONS appear.
  7653.      `do-elts' is used when only side-effects of PROC are of interest
  7654.      and its return value is unspecified.  `map-elts' returns a
  7655.      collection (actually a vector) of the results of the applications
  7656.      of PROC.
  7657.  
  7658.      Example:
  7659.           (map-elts + (list 1 2 3) (vector 1 2 3))
  7660.              => #(2 4 6)
  7661.  
  7662.  - Procedure: map-keys PROC . COLLECTIONS
  7663.  - Procedure: do-keys PROC . COLLECTIONS
  7664.      These are analogous to `map-elts' and `do-elts', but each
  7665.      iteration is over the COLLECTIONS' *keys* rather than their
  7666.      elements.
  7667.  
  7668.      Example:
  7669.           (map-keys + (list 1 2 3) (vector 1 2 3))
  7670.              => #(0 2 4)
  7671.  
  7672.  - Procedure: for-each-key COLLECTION PROC
  7673.  - Procedure: for-each-elt COLLECTION PROC
  7674.      These are like `do-keys' and `do-elts' but only for a single
  7675.      collection; they are potentially more efficient.
  7676.  
  7677.  - Function: reduce PROC SEED . COLLECTIONS
  7678.      A generalization of the list-based `comlist:reduce-init' (*note
  7679.      Lists as sequences::.) to collections which will shadow the
  7680.      list-based version if `(require 'collect)' follows `(require
  7681.      'common-list-functions)' (*note Common List Functions::.).
  7682.  
  7683.      Examples:
  7684.           (reduce + 0 (vector 1 2 3))
  7685.              => 6
  7686.           (reduce union '() '((a b c) (b c d) (d a)))
  7687.              => (c b d a).
  7688.  
  7689.  - Function: any? PRED . COLLECTIONS
  7690.      A generalization of the list-based `some' (*note Lists as
  7691.      sequences::.) to collections.
  7692.  
  7693.      Example:
  7694.           (any? odd? (list 2 3 4 5))
  7695.              => #t
  7696.  
  7697.  - Function: every? PRED . COLLECTIONS
  7698.      A generalization of the list-based `every' (*note Lists as
  7699.      sequences::.) to collections.
  7700.  
  7701.      Example:
  7702.           (every? collection? '((1 2) #(1 2)))
  7703.              => #t
  7704.  
  7705.  - Function: empty? COLLECTION
  7706.      Returns `#t' iff there are no elements in COLLECTION.
  7707.  
  7708.      `(empty? COLLECTION) == (zero? (size COLLECTION))'
  7709.  
  7710.  - Function: size COLLECTION
  7711.      Returns the number of elements in COLLECTION.
  7712.  
  7713.  - Function: Setter LIST-REF
  7714.      See *Note Setters:: for a definition of "setter".  N.B.  `(setter
  7715.      list-ref)' doesn't work properly for element 0 of a list.
  7716.  
  7717.   Here is a sample collection: `simple-table' which is also a `table'.
  7718.      (define-predicate TABLE?)
  7719.      (define-operation (LOOKUP table key failure-object))
  7720.      (define-operation (ASSOCIATE! table key value)) ;; returns key
  7721.      (define-operation (REMOVE! table key))          ;; returns value
  7722.      
  7723.      (define (MAKE-SIMPLE-TABLE)
  7724.        (let ( (table (list)) )
  7725.          (object
  7726.           ;; table behaviors
  7727.           ((TABLE? self) #t)
  7728.           ((SIZE self) (size table))
  7729.           ((PRINT self port) (format port "#<SIMPLE-TABLE>"))
  7730.           ((LOOKUP self key failure-object)
  7731.            (cond
  7732.             ((assq key table) => cdr)
  7733.             (else failure-object)
  7734.             ))
  7735.           ((ASSOCIATE! self key value)
  7736.            (cond
  7737.             ((assq key table)
  7738.              => (lambda (bucket) (set-cdr! bucket value) key))
  7739.             (else
  7740.              (set! table (cons (cons key value) table))
  7741.              key)
  7742.             ))
  7743.           ((REMOVE! self key);; returns old value
  7744.            (cond
  7745.             ((null? table) (slib:error "TABLE:REMOVE! Key not found: " key))
  7746.             ((eq? key (caar table))
  7747.              (let ( (value (cdar table)) )
  7748.                (set! table (cdr table))
  7749.                value)
  7750.              )
  7751.             (else
  7752.              (let loop ( (last table) (this (cdr table)) )
  7753.                (cond
  7754.                 ((null? this)
  7755.                  (slib:error "TABLE:REMOVE! Key not found: " key))
  7756.                 ((eq? key (caar this))
  7757.                  (let ( (value (cdar this)) )
  7758.                    (set-cdr! last (cdr this))
  7759.                    value)
  7760.                  )
  7761.                 (else
  7762.                  (loop (cdr last) (cdr this)))
  7763.                 ) ) )
  7764.             ))
  7765.           ;; collection behaviors
  7766.           ((COLLECTION? self) #t)
  7767.           ((GEN-KEYS self) (collect:list-gen-elts (map car table)))
  7768.           ((GEN-ELTS self) (collect:list-gen-elts (map cdr table)))
  7769.           ((FOR-EACH-KEY self proc)
  7770.            (for-each (lambda (bucket) (proc (car bucket))) table)
  7771.            )
  7772.           ((FOR-EACH-ELT self proc)
  7773.            (for-each (lambda (bucket) (proc (cdr bucket))) table)
  7774.            )
  7775.           ) ) )
  7776.  
  7777. 
  7778. File: slib.info,  Node: Dynamic Data Type,  Next: Hash Tables,  Prev: Collections,  Up: Data Structures
  7779.  
  7780. Dynamic Data Type
  7781. -----------------
  7782.  
  7783.   `(require 'dynamic)'
  7784.  
  7785.  - Function: make-dynamic OBJ
  7786.      Create and returns a new "dynamic" whose global value is OBJ.
  7787.  
  7788.  - Function: dynamic? OBJ
  7789.      Returns true if and only if OBJ is a dynamic.  No object
  7790.      satisfying `dynamic?' satisfies any of the other standard type
  7791.      predicates.
  7792.  
  7793.  - Function: dynamic-ref DYN
  7794.      Return the value of the given dynamic in the current dynamic
  7795.      environment.
  7796.  
  7797.  - Procedure: dynamic-set! DYN OBJ
  7798.      Change the value of the given dynamic to OBJ in the current
  7799.      dynamic environment.  The returned value is unspecified.
  7800.  
  7801.  - Function: call-with-dynamic-binding DYN OBJ THUNK
  7802.      Invoke and return the value of the given thunk in a new, nested
  7803.      dynamic environment in which the given dynamic has been bound to a
  7804.      new location whose initial contents are the value OBJ.  This
  7805.      dynamic environment has precisely the same extent as the
  7806.      invocation of the thunk and is thus captured by continuations
  7807.      created within that invocation and re-established by those
  7808.      continuations when they are invoked.
  7809.  
  7810.   The `dynamic-bind' macro is not implemented.
  7811.  
  7812. 
  7813. File: slib.info,  Node: Hash Tables,  Next: Hashing,  Prev: Dynamic Data Type,  Up: Data Structures
  7814.  
  7815. Hash Tables
  7816. -----------
  7817.  
  7818.   `(require 'hash-table)'
  7819.  
  7820.  - Function: predicate->hash PRED
  7821.      Returns a hash function (like `hashq', `hashv', or `hash')
  7822.      corresponding to the equality predicate PRED.  PRED should be
  7823.      `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?', `string=?', or
  7824.      `string-ci=?'.
  7825.  
  7826.   A hash table is a vector of association lists.
  7827.  
  7828.  - Function: make-hash-table K
  7829.      Returns a vector of K empty (association) lists.
  7830.  
  7831.   Hash table functions provide utilities for an associative database.
  7832. These functions take an equality predicate, PRED, as an argument.  PRED
  7833. should be `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?',
  7834. `string=?', or `string-ci=?'.
  7835.  
  7836.  - Function: predicate->hash-asso PRED
  7837.      Returns a hash association function of 2 arguments, KEY and
  7838.      HASHTAB, corresponding to PRED.  The returned function returns a
  7839.      key-value pair whose key is PRED-equal to its first argument or
  7840.      `#f' if no key in HASHTAB is PRED-equal to the first argument.
  7841.  
  7842.  - Function: hash-inquirer PRED
  7843.      Returns a procedure of 3 arguments, `hashtab' and `key', which
  7844.      returns the value associated with `key' in `hashtab' or `#f' if
  7845.      key does not appear in `hashtab'.
  7846.  
  7847.  - Function: hash-associator PRED
  7848.      Returns a procedure of 3 arguments, HASHTAB, KEY, and VALUE, which
  7849.      modifies HASHTAB so that KEY and VALUE associated.  Any previous
  7850.      value associated with KEY will be lost.
  7851.  
  7852.  - Function: hash-remover PRED
  7853.      Returns a procedure of 2 arguments, HASHTAB and KEY, which
  7854.      modifies HASHTAB so that the association whose key is KEY is
  7855.      removed.
  7856.  
  7857.  - Function: hash-map PROC HASH-TABLE
  7858.      Returns a new hash table formed by mapping PROC over the keys and
  7859.      values of HASH-TABLE.  PROC must be a function of 2 arguments
  7860.      which returns the new value part.
  7861.  
  7862.  - Function: hash-for-each PROC HASH-TABLE
  7863.      Applies PROC to each pair of keys and values of HASH-TABLE.  PROC
  7864.      must be a function of 2 arguments.  The returned value is
  7865.      unspecified.
  7866.  
  7867. 
  7868. File: slib.info,  Node: Hashing,  Next: Object,  Prev: Hash Tables,  Up: Data Structures
  7869.  
  7870. Hashing
  7871. -------
  7872.  
  7873.   `(require 'hash)'
  7874.  
  7875.   These hashing functions are for use in quickly classifying objects.
  7876. Hash tables use these functions.
  7877.  
  7878.  - Function: hashq OBJ K
  7879.  - Function: hashv OBJ K
  7880.  - Function: hash OBJ K
  7881.      Returns an exact non-negative integer less than K.  For each
  7882.      non-negative integer less than K there are arguments OBJ for which
  7883.      the hashing functions applied to OBJ and K returns that integer.
  7884.  
  7885.      For `hashq', `(eq? obj1 obj2)' implies `(= (hashq obj1 k) (hashq
  7886.      obj2))'.
  7887.  
  7888.      For `hashv', `(eqv? obj1 obj2)' implies `(= (hashv obj1 k) (hashv
  7889.      obj2))'.
  7890.  
  7891.      For `hash', `(equal? obj1 obj2)' implies `(= (hash obj1 k) (hash
  7892.      obj2))'.
  7893.  
  7894.      `hash', `hashv', and `hashq' return in time bounded by a constant.
  7895.      Notice that items having the same `hash' implies the items have
  7896.      the same `hashv' implies the items have the same `hashq'.
  7897.  
  7898.   `(require 'sierpinski)'
  7899.  
  7900.  - Function: make-sierpinski-indexer MAX-COORDINATE
  7901.      Returns a procedure (eg hash-function) of 2 numeric arguments which
  7902.      preserves *nearness* in its mapping from NxN to N.
  7903.  
  7904.      MAX-COORDINATE is the maximum coordinate (a positive integer) of a
  7905.      population of points.  The returned procedures is a function that
  7906.      takes the x and y coordinates of a point, (non-negative integers)
  7907.      and returns an integer corresponding to the relative position of
  7908.      that point along a Sierpinski curve.  (You can think of this as
  7909.      computing a (pseudo-) inverse of the Sierpinski spacefilling
  7910.      curve.)
  7911.  
  7912.      Example use: Make an indexer (hash-function) for integer points
  7913.      lying in square of integer grid points [0,99]x[0,99]:
  7914.           (define space-key (make-sierpinski-indexer 100))
  7915.      Now let's compute the index of some points:
  7916.           (space-key 24 78)               => 9206
  7917.           (space-key 23 80)               => 9172
  7918.  
  7919.      Note that locations (24, 78) and (23, 80) are near in index and
  7920.      therefore, because the Sierpinski spacefilling curve is
  7921.      continuous, we know they must also be near in the plane.  Nearness
  7922.      in the plane does not, however, necessarily correspond to nearness
  7923.      in index, although it *tends* to be so.
  7924.  
  7925.      Example applications:
  7926.         * Sort points by Sierpinski index to get heuristic solution to
  7927.           *travelling salesman problem*.  For details of performance,
  7928.           see L. Platzman and J. Bartholdi, "Spacefilling curves and the
  7929.           Euclidean travelling salesman problem", JACM 36(4):719-737
  7930.           (October 1989) and references therein.
  7931.  
  7932.         * Use Sierpinski index as key by which to store 2-dimensional
  7933.           data in a 1-dimensional data structure (such as a table).
  7934.           Then locations that are near each other in 2-d space will
  7935.           tend to be near each other in 1-d data structure; and
  7936.           locations that are near in 1-d data structure will be near in
  7937.           2-d space.  This can significantly speed retrieval from
  7938.           secondary storage because contiguous regions in the plane
  7939.           will tend to correspond to contiguous regions in secondary
  7940.           storage.  (This is a standard technique for managing CAD/CAM
  7941.           or geographic data.)
  7942.  
  7943.  
  7944.   `(require 'soundex)'
  7945.  
  7946.  - Function: soundex NAME
  7947.      Computes the *soundex* hash of NAME.  Returns a string of an
  7948.      initial letter and up to three digits between 0 and 6.  Soundex
  7949.      supposedly has the property that names that sound similar in normal
  7950.      English pronunciation tend to map to the same key.
  7951.  
  7952.      Soundex was a classic algorithm used for manual filing of personal
  7953.      records before the advent of computers.  It performs adequately for
  7954.      English names but has trouble with other nationalities.
  7955.  
  7956.      See Knuth, Vol. 3 `Sorting and searching', pp 391-2
  7957.  
  7958.      To manage unusual inputs, `soundex' omits all non-alphabetic
  7959.      characters.  Consequently, in this implementation:
  7960.  
  7961.           (soundex <string of blanks>)    => ""
  7962.           (soundex "")                    => ""
  7963.  
  7964.      Examples from Knuth:
  7965.  
  7966.           (map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
  7967.                                  "Lloyd" "Lukasiewicz"))
  7968.                   => ("E460" "G200" "H416" "K530" "L300" "L222")
  7969.           
  7970.           (map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
  7971.                                   "Ladd" "Lissajous"))
  7972.                   => ("E460" "G200" "H416" "K530" "L300" "L222")
  7973.  
  7974.      Some cases in which the algorithm fails (Knuth):
  7975.  
  7976.           (map soundex '("Rogers" "Rodgers"))     => ("R262" "R326")
  7977.           
  7978.           (map soundex '("Sinclair" "St. Clair")) => ("S524" "S324")
  7979.           
  7980.           (map soundex '("Tchebysheff" "Chebyshev")) => ("T212" "C121")
  7981.  
  7982. 
  7983. File: slib.info,  Node: Object,  Next: Priority Queues,  Prev: Hashing,  Up: Data Structures
  7984.  
  7985. Macroless Object System
  7986. -----------------------
  7987.  
  7988.   `(require 'object)'
  7989.  
  7990.   This is the Macroless Object System written by Wade Humeniuk
  7991. (whumeniu@datap.ca).  Conceptual Tributes: *Note Yasos::, MacScheme's
  7992. %object, CLOS, Lack of R4RS macros.
  7993.  
  7994. Concepts
  7995. --------
  7996.  
  7997. OBJECT
  7998.      An object is an ordered association-list (by `eq?') of methods
  7999.      (procedures).  Methods can be added (`make-method!'), deleted
  8000.      (`unmake-method!') and retrieved (`get-method').  Objects may
  8001.      inherit methods from other objects.  The object binds to the
  8002.      environment it was created in, allowing closures to be used to
  8003.      hide private procedures and data.
  8004.  
  8005. GENERIC-METHOD
  8006.      A generic-method associates (in terms of `eq?') object's method.
  8007.      This allows scheme function style to be used for objects.  The
  8008.      calling scheme for using a generic method is `(generic-method
  8009.      object param1 param2 ...)'.
  8010.  
  8011. METHOD
  8012.      A method is a procedure that exists in the object.  To use a method
  8013.      get-method must be called to look-up the method.  Generic methods
  8014.      implement the get-method functionality.  Methods may be added to an
  8015.      object associated with any scheme obj in terms of eq?
  8016.  
  8017. GENERIC-PREDICATE
  8018.      A generic method that returns a boolean value for any scheme obj.
  8019.  
  8020. PREDICATE
  8021.      A object's method asscociated with a generic-predicate. Returns
  8022.      `#t'.
  8023.  
  8024. Procedures
  8025. ----------
  8026.  
  8027.  - Function: make-object ANCESTOR ...
  8028.      Returns an object.  Current object implementation is a tagged
  8029.      vector.  ANCESTORs are optional and must be objects in terms of
  8030.      object?.  ANCESTORs methods are included in the object.  Multiple
  8031.      ANCESTORs might associate the same generic-method with a method.
  8032.      In this case the method of the ANCESTOR first appearing in the
  8033.      list is the one returned by `get-method'.
  8034.  
  8035.  - Function: object? OBJ
  8036.      Returns boolean value whether OBJ was created by make-object.
  8037.  
  8038.  - Function: make-generic-method EXCEPTION-PROCEDURE
  8039.      Returns a procedure which be associated with an object's methods.
  8040.      If EXCEPTION-PROCEDURE is specified then it is used to process
  8041.      non-objects.
  8042.  
  8043.  - Function: make-generic-predicate
  8044.      Returns a boolean procedure for any scheme object.
  8045.  
  8046.  - Function: make-method! OBJECT GENERIC-METHOD METHOD
  8047.      Associates METHOD to the GENERIC-METHOD in the object.  The METHOD
  8048.      overrides any previous association with the GENERIC-METHOD within
  8049.      the object.  Using `unmake-method!'  will restore the object's
  8050.      previous association with the GENERIC-METHOD.  METHOD must be a
  8051.      procedure.
  8052.  
  8053.  - Function: make-predicate! OBJECT GENERIC-PRECIATE
  8054.      Makes a predicate method associated with the GENERIC-PREDICATE.
  8055.  
  8056.  - Function: unmake-method! OBJECT GENERIC-METHOD
  8057.      Removes an object's association with a GENERIC-METHOD .
  8058.  
  8059.  - Function: get-method OBJECT GENERIC-METHOD
  8060.      Returns the object's method associated (if any) with the
  8061.      GENERIC-METHOD.  If no associated method exists an error is
  8062.      flagged.
  8063.  
  8064. Examples
  8065. --------
  8066.  
  8067.      (require 'object)
  8068.      
  8069.      (define instantiate (make-generic-method))
  8070.      
  8071.      (define (make-instance-object . ancestors)
  8072.        (define self (apply make-object
  8073.                            (map (lambda (obj) (instantiate obj)) ancestors)))
  8074.        (make-method! self instantiate (lambda (self) self))
  8075.        self)
  8076.      
  8077.      (define who (make-generic-method))
  8078.      (define imigrate! (make-generic-method))
  8079.      (define emigrate! (make-generic-method))
  8080.      (define describe (make-generic-method))
  8081.      (define name (make-generic-method))
  8082.      (define address (make-generic-method))
  8083.      (define members (make-generic-method))
  8084.      
  8085.      (define society
  8086.        (let ()
  8087.          (define self (make-instance-object))
  8088.          (define population '())
  8089.          (make-method! self imigrate!
  8090.                        (lambda (new-person)
  8091.                          (if (not (eq? new-person self))
  8092.                              (set! population (cons new-person population)))))
  8093.          (make-method! self emigrate!
  8094.                        (lambda (person)
  8095.                          (if (not (eq? person self))
  8096.                              (set! population
  8097.                                    (comlist:remove-if (lambda (member)
  8098.                                                         (eq? member person))
  8099.                                                       population)))))
  8100.          (make-method! self describe
  8101.                        (lambda (self)
  8102.                          (map (lambda (person) (describe person)) population)))
  8103.          (make-method! self who
  8104.                        (lambda (self) (map (lambda (person) (name person))
  8105.                                            population)))
  8106.          (make-method! self members (lambda (self) population))
  8107.          self))
  8108.      
  8109.      (define (make-person %name %address)
  8110.        (define self (make-instance-object society))
  8111.        (make-method! self name (lambda (self) %name))
  8112.        (make-method! self address (lambda (self) %address))
  8113.        (make-method! self who (lambda (self) (name self)))
  8114.        (make-method! self instantiate
  8115.                      (lambda (self)
  8116.                        (make-person (string-append (name self) "-son-of")
  8117.                                     %address)))
  8118.        (make-method! self describe
  8119.                      (lambda (self) (list (name self) (address self))))
  8120.        (imigrate! self)
  8121.        self)
  8122.  
  8123. Inverter Documentation
  8124. ......................
  8125.  
  8126.   Inheritance:
  8127.              <inverter>::(<number> <description>)
  8128.   Generic-methods
  8129.              <inverter>::value      => <number>::value
  8130.              <inverter>::set-value! => <number>::set-value!
  8131.              <inverter>::describe   => <description>::describe
  8132.              <inverter>::help
  8133.              <inverter>::invert
  8134.              <inverter>::inverter?
  8135.  
  8136. Number Documention
  8137. ..................
  8138.  
  8139.   Inheritance
  8140.              <number>::()
  8141.   Slots
  8142.              <number>::<x>
  8143.   Generic Methods
  8144.              <number>::value
  8145.              <number>::set-value!
  8146.  
  8147. Inverter code
  8148. .............
  8149.  
  8150.      (require 'object)
  8151.      
  8152.      (define value (make-generic-method (lambda (val) val)))
  8153.      (define set-value! (make-generic-method))
  8154.      (define invert (make-generic-method
  8155.                      (lambda (val)
  8156.                        (if (number? val)
  8157.                            (/ 1 val)
  8158.                            (error "Method not supported:" val)))))
  8159.      (define noop (make-generic-method))
  8160.      (define inverter? (make-generic-predicate))
  8161.      (define describe (make-generic-method))
  8162.      (define help (make-generic-method))
  8163.      
  8164.      (define (make-number x)
  8165.        (define self (make-object))
  8166.        (make-method! self value (lambda (this) x))
  8167.        (make-method! self set-value!
  8168.                      (lambda (this new-value) (set! x new-value)))
  8169.        self)
  8170.      
  8171.      (define (make-description str)
  8172.        (define self (make-object))
  8173.        (make-method! self describe (lambda (this) str))
  8174.        (make-method! self help (lambda (this) "Help not available"))
  8175.        self)
  8176.      
  8177.      (define (make-inverter)
  8178.        (let* ((self (make-object
  8179.                      (make-number 1)
  8180.                      (make-description "A number which can be inverted")))
  8181.               (<value> (get-method self value)))
  8182.          (make-method! self invert (lambda (self) (/ 1 (<value> self))))
  8183.          (make-predicate! self inverter?)
  8184.          (unmake-method! self help)
  8185.          (make-method! self help
  8186.                        (lambda (self)
  8187.                          (display "Inverter Methods:") (newline)
  8188.                          (display "  (value inverter) ==> n") (newline)))
  8189.          self))
  8190.      
  8191.      ;;;; Try it out
  8192.      
  8193.      (define invert! (make-generic-method))
  8194.      
  8195.      (define x (make-inverter))
  8196.      
  8197.      (make-method! x invert! (lambda (x) (set-value! x (/ 1 (value x)))))
  8198.      
  8199.      (value x)                       => 1
  8200.      (set-value! x 33)               => undefined
  8201.      (invert! x)                     => undefined
  8202.      (value x)                       => 1/33
  8203.      
  8204.      (unmake-method! x invert!)      => undefined
  8205.      
  8206.      (invert! x)                     error-->  ERROR: Method not supported: x
  8207.  
  8208. 
  8209. File: slib.info,  Node: Priority Queues,  Next: Queues,  Prev: Object,  Up: Data Structures
  8210.  
  8211. Priority Queues
  8212. ---------------
  8213.  
  8214.   `(require 'priority-queue)'
  8215.  
  8216.  - Function: make-heap PRED<?
  8217.      Returns a binary heap suitable which can be used for priority queue
  8218.      operations.
  8219.  
  8220.  - Function: heap-length HEAP
  8221.      Returns the number of elements in HEAP.
  8222.  
  8223.  - Procedure: heap-insert! HEAP ITEM
  8224.      Inserts ITEM into HEAP.  ITEM can be inserted multiple times.  The
  8225.      value returned is unspecified.
  8226.  
  8227.  - Function: heap-extract-max! HEAP
  8228.      Returns the item which is larger than all others according to the
  8229.      PRED<? argument to `make-heap'.  If there are no items in HEAP, an
  8230.      error is signaled.
  8231.  
  8232.   The algorithm for priority queues was taken from `Introduction to
  8233. Algorithms' by T. Cormen, C. Leiserson, R. Rivest.  1989 MIT Press.
  8234.  
  8235. 
  8236. File: slib.info,  Node: Queues,  Next: Records,  Prev: Priority Queues,  Up: Data Structures
  8237.  
  8238. Queues
  8239. ------
  8240.  
  8241.   `(require 'queue)'
  8242.  
  8243.   A "queue" is a list where elements can be added to both the front and
  8244. rear, and removed from the front (i.e., they are what are often called
  8245. "dequeues").  A queue may also be used like a stack.
  8246.  
  8247.  - Function: make-queue
  8248.      Returns a new, empty queue.
  8249.  
  8250.  - Function: queue? OBJ
  8251.      Returns `#t' if OBJ is a queue.
  8252.  
  8253.  - Function: queue-empty? Q
  8254.      Returns `#t' if the queue Q is empty.
  8255.  
  8256.  - Procedure: queue-push! Q DATUM
  8257.      Adds DATUM to the front of queue Q.
  8258.  
  8259.  - Procedure: enquque! Q DATUM
  8260.      Adds DATUM to the rear of queue Q.
  8261.  
  8262.   All of the following functions raise an error if the queue Q is empty.
  8263.  
  8264.  - Function: queue-front Q
  8265.      Returns the datum at the front of the queue Q.
  8266.  
  8267.  - Function: queue-rear Q
  8268.      Returns the datum at the rear of the queue Q.
  8269.  
  8270.  - Prcoedure: queue-pop! Q
  8271.  - Procedure: dequeue! Q
  8272.      Both of these procedures remove and return the datum at the front
  8273.      of the queue.  `queue-pop!' is used to suggest that the queue is
  8274.      being used like a stack.
  8275.  
  8276. 
  8277. File: slib.info,  Node: Records,  Next: Structures,  Prev: Queues,  Up: Data Structures
  8278.  
  8279. Records
  8280. -------
  8281.  
  8282.   `(require 'record)'
  8283.  
  8284.   The Record package provides a facility for user to define their own
  8285. record data types.
  8286.  
  8287.  - Function: make-record-type TYPE-NAME FIELD-NAMES
  8288.      Returns a "record-type descriptor", a value representing a new data
  8289.      type disjoint from all others.  The TYPE-NAME argument must be a
  8290.      string, but is only used for debugging purposes (such as the
  8291.      printed representation of a record of the new type).  The
  8292.      FIELD-NAMES argument is a list of symbols naming the "fields" of a
  8293.      record of the new type.  It is an error if the list contains any
  8294.      duplicates.  It is unspecified how record-type descriptors are
  8295.      represented.
  8296.  
  8297.  - Function: record-constructor RTD [FIELD-NAMES]
  8298.      Returns a procedure for constructing new members of the type
  8299.      represented by RTD.  The returned procedure accepts exactly as
  8300.      many arguments as there are symbols in the given list,
  8301.      FIELD-NAMES; these are used, in order, as the initial values of
  8302.      those fields in a new record, which is returned by the constructor
  8303.      procedure.  The values of any fields not named in that list are
  8304.      unspecified.  The FIELD-NAMES argument defaults to the list of
  8305.      field names in the call to `make-record-type' that created the
  8306.      type represented by RTD; if the FIELD-NAMES argument is provided,
  8307.      it is an error if it contains any duplicates or any symbols not in
  8308.      the default list.
  8309.  
  8310.  - Function: record-predicate RTD
  8311.      Returns a procedure for testing membership in the type represented
  8312.      by RTD.  The returned procedure accepts exactly one argument and
  8313.      returns a true value if the argument is a member of the indicated
  8314.      record type; it returns a false value otherwise.
  8315.  
  8316.  - Function: record-accessor RTD FIELD-NAME
  8317.      Returns a procedure for reading the value of a particular field of
  8318.      a member of the type represented by RTD.  The returned procedure
  8319.      accepts exactly one argument which must be a record of the
  8320.      appropriate type; it returns the current value of the field named
  8321.      by the symbol FIELD-NAME in that record.  The symbol FIELD-NAME
  8322.      must be a member of the list of field-names in the call to
  8323.      `make-record-type' that created the type represented by RTD.
  8324.  
  8325.  - Function: record-modifier RTD FIELD-NAME
  8326.      Returns a procedure for writing the value of a particular field of
  8327.      a member of the type represented by RTD.  The returned procedure
  8328.      accepts exactly two arguments: first, a record of the appropriate
  8329.      type, and second, an arbitrary Scheme value; it modifies the field
  8330.      named by the symbol FIELD-NAME in that record to contain the given
  8331.      value.  The returned value of the modifier procedure is
  8332.      unspecified.  The symbol FIELD-NAME must be a member of the list
  8333.      of field-names in the call to `make-record-type' that created the
  8334.      type represented by RTD.
  8335.  
  8336.   In May of 1996, as a product of discussion on the `rrrs-authors'
  8337. mailing list, I rewrote `record.scm' to portably implement type
  8338. disjointness for record data types.
  8339.  
  8340.   As long as an implementation's procedures are opaque and the `record'
  8341. code is loaded before other programs, this will give disjoint record
  8342. types which are unforgeable and incorruptible by R4RS procedures.
  8343.  
  8344.   As a consequence, the procedures `record?', `record-type-descriptor',
  8345. `record-type-name'.and `record-type-field-names' are no longer
  8346. supported.
  8347.  
  8348. 
  8349. File: slib.info,  Node: Structures,  Prev: Records,  Up: Data Structures
  8350.  
  8351. Structures
  8352. ----------
  8353.  
  8354.   `(require 'struct)' (uses defmacros)
  8355.  
  8356.   `defmacro's which implement "records" from the book `Essentials of
  8357. Programming Languages' by Daniel P. Friedman, M.  Wand and C.T. Haynes.
  8358. Copyright 1992 Jeff Alexander, Shinnder Lee, and Lewis Patterson
  8359.  
  8360.   Matthew McDonald <mafm@cs.uwa.edu.au> added field setters.
  8361.  
  8362.  - Macro: define-record TAG (VAR1 VAR2 ...)
  8363.      Defines several functions pertaining to record-name TAG:
  8364.  
  8365.       - Function: make-TAG VAR1 VAR2 ...
  8366.  
  8367.       - Function: TAG? OBJ
  8368.  
  8369.       - Function: TAG->VAR1 OBJ
  8370.  
  8371.       - Function: TAG->VAR2 OBJ
  8372.      ...
  8373.  
  8374.       - Function: set-TAG-VAR1! OBJ VAL
  8375.  
  8376.       - Function: set-TAG-VAR2! OBJ VAL
  8377.      ...
  8378.  
  8379.      Here is an example of its use.
  8380.  
  8381.           (define-record term (operator left right))
  8382.           => #<unspecified>
  8383.           (define foo (make-term 'plus  1 2))
  8384.           => foo
  8385.           (term->left foo)
  8386.           => 1
  8387.           (set-term-left! foo 2345)
  8388.           => #<unspecified>
  8389.           (term->left foo)
  8390.           => 2345
  8391.  
  8392.  - Macro: variant-case EXP (TAG (VAR1 VAR2 ...) BODY) ...
  8393.      executes the following for the matching clause:
  8394.  
  8395.           ((lambda (VAR1 VAR ...) BODY)
  8396.              (TAG->VAR1 EXP)
  8397.              (TAG->VAR2 EXP) ...)
  8398.  
  8399. 
  8400. File: slib.info,  Node: Procedures,  Next: Standards Support,  Prev: Data Structures,  Up: Other Packages
  8401.  
  8402. Procedures
  8403. ==========
  8404.  
  8405.   Anything that doesn't fall neatly into any of the other categories
  8406. winds up here.
  8407.  
  8408. * Menu:
  8409.  
  8410. * Common List Functions::       'common-list-functions
  8411. * Tree Operations::             'tree
  8412. * Chapter Ordering::            'chapter-order
  8413. * Sorting::                     'sort
  8414. * Topological Sort::            Keep your socks on.
  8415. * String-Case::                 'string-case
  8416. * String Ports::                'string-port
  8417. * String Search::               Also Search from a Port.
  8418. * Line I/O::                    'line-i/o
  8419. * Multi-Processing::            'process
  8420.  
  8421. 
  8422. File: slib.info,  Node: Common List Functions,  Next: Tree Operations,  Prev: Procedures,  Up: Procedures
  8423.  
  8424. Common List Functions
  8425. ---------------------
  8426.  
  8427.   `(require 'common-list-functions)'
  8428.  
  8429.   The procedures below follow the Common LISP equivalents apart from
  8430. optional arguments in some cases.
  8431.  
  8432. * Menu:
  8433.  
  8434. * List construction::
  8435. * Lists as sets::
  8436. * Lists as sequences::
  8437. * Destructive list operations::
  8438. * Non-List functions::
  8439.  
  8440. 
  8441. File: slib.info,  Node: List construction,  Next: Lists as sets,  Prev: Common List Functions,  Up: Common List Functions
  8442.  
  8443. List construction
  8444. .................
  8445.  
  8446.  - Function: make-list K . INIT
  8447.      `make-list' creates and returns a list of K elements.  If INIT is
  8448.      included, all elements in the list are initialized to INIT.
  8449.  
  8450.      Example:
  8451.           (make-list 3)
  8452.              => (#<unspecified> #<unspecified> #<unspecified>)
  8453.           (make-list 5 'foo)
  8454.              => (foo foo foo foo foo)
  8455.  
  8456.  - Function: list* X . Y
  8457.      Works like `list' except that the cdr of the last pair is the last
  8458.      argument unless there is only one argument, when the result is
  8459.      just that argument.  Sometimes called `cons*'.  E.g.:
  8460.           (list* 1)
  8461.              => 1
  8462.           (list* 1 2 3)
  8463.              => (1 2 . 3)
  8464.           (list* 1 2 '(3 4))
  8465.              => (1 2 3 4)
  8466.           (list* ARGS '())
  8467.              == (list ARGS)
  8468.  
  8469.  - Function: copy-list LST
  8470.      `copy-list' makes a copy of LST using new pairs and returns it.
  8471.      Only the top level of the list is copied, i.e., pairs forming
  8472.      elements of the copied list remain `eq?' to the corresponding
  8473.      elements of the original; the copy is, however, not `eq?' to the
  8474.      original, but is `equal?' to it.
  8475.  
  8476.      Example:
  8477.           (copy-list '(foo foo foo))
  8478.              => (foo foo foo)
  8479.           (define q '(foo bar baz bang))
  8480.           (define p q)
  8481.           (eq? p q)
  8482.              => #t
  8483.           (define r (copy-list q))
  8484.           (eq? q r)
  8485.              => #f
  8486.           (equal? q r)
  8487.              => #t
  8488.           (define bar '(bar))
  8489.           (eq? bar (car (copy-list (list bar 'foo))))
  8490.           => #t
  8491.  
  8492. 
  8493. File: slib.info,  Node: Lists as sets,  Next: Lists as sequences,  Prev: List construction,  Up: Common List Functions
  8494.  
  8495. Lists as sets
  8496. .............
  8497.  
  8498.   `eqv?' is used to test for membership by procedures which treat lists
  8499. as sets.
  8500.  
  8501.  - Function: adjoin E L
  8502.      `adjoin' returns the adjoint of the element E and the list L.
  8503.      That is, if E is in L, `adjoin' returns L, otherwise, it returns
  8504.      `(cons E L)'.
  8505.  
  8506.      Example:
  8507.           (adjoin 'baz '(bar baz bang))
  8508.              => (bar baz bang)
  8509.           (adjoin 'foo '(bar baz bang))
  8510.              => (foo bar baz bang)
  8511.  
  8512.  - Function: union L1 L2
  8513.      `union' returns the combination of L1 and L2.  Duplicates between
  8514.      L1 and L2 are culled.  Duplicates within L1 or within L2 may or
  8515.      may not be removed.
  8516.  
  8517.      Example:
  8518.           (union '(1 2 3 4) '(5 6 7 8))
  8519.              => (4 3 2 1 5 6 7 8)
  8520.           (union '(1 2 3 4) '(3 4 5 6))
  8521.              => (2 1 3 4 5 6)
  8522.  
  8523.  - Function: intersection L1 L2
  8524.      `intersection' returns all elements that are in both L1 and L2.
  8525.  
  8526.      Example:
  8527.           (intersection '(1 2 3 4) '(3 4 5 6))
  8528.              => (3 4)
  8529.           (intersection '(1 2 3 4) '(5 6 7 8))
  8530.              => ()
  8531.  
  8532.  - Function: set-difference L1 L2
  8533.      `set-difference' returns all elements that are in L1 but not in L2.      |
  8534.  
  8535.      Example:
  8536.           (set-difference '(1 2 3 4) '(3 4 5 6))
  8537.              => (1 2)
  8538.           (set-difference '(1 2 3 4) '(1 2 3 4 5 6))
  8539.              => ()
  8540.  
  8541.  - Function: member-if PRED LST
  8542.      `member-if' returns LST if `(PRED ELEMENT)' is `#t' for any
  8543.      ELEMENT in LST.  Returns `#f' if PRED does not apply to any
  8544.      ELEMENT in LST.
  8545.  
  8546.      Example:
  8547.           (member-if vector? '(1 2 3 4))
  8548.              => #f
  8549.           (member-if number? '(1 2 3 4))
  8550.              => (1 2 3 4)
  8551.  
  8552.  - Function: some PRED LST . MORE-LSTS
  8553.      PRED is a boolean function of as many arguments as there are list
  8554.      arguments to `some' i.e., LST plus any optional arguments.  PRED
  8555.      is applied to successive elements of the list arguments in order.
  8556.      `some' returns `#t' as soon as one of these applications returns
  8557.      `#t', and is `#f' if none returns `#t'.  All the lists should have
  8558.      the same length.
  8559.  
  8560.      Example:
  8561.           (some odd? '(1 2 3 4))
  8562.              => #t
  8563.           
  8564.           (some odd? '(2 4 6 8))
  8565.              => #f
  8566.           
  8567.           (some > '(2 3) '(1 4))
  8568.              => #f
  8569.  
  8570.  - Function: every PRED LST . MORE-LSTS
  8571.      `every' is analogous to `some' except it returns `#t' if every
  8572.      application of PRED is `#t' and `#f' otherwise.
  8573.  
  8574.      Example:
  8575.           (every even? '(1 2 3 4))
  8576.              => #f
  8577.           
  8578.           (every even? '(2 4 6 8))
  8579.              => #t
  8580.           
  8581.           (every > '(2 3) '(1 4))
  8582.              => #f
  8583.  
  8584.  - Function: notany PRED . LST
  8585.      `notany' is analogous to `some' but returns `#t' if no application
  8586.      of PRED returns `#t' or `#f' as soon as any one does.
  8587.  
  8588.  - Function: notevery PRED . LST
  8589.      `notevery' is analogous to `some' but returns `#t' as soon as an
  8590.      application of PRED returns `#f', and `#f' otherwise.
  8591.  
  8592.      Example:
  8593.           (notevery even? '(1 2 3 4))
  8594.              => #t
  8595.           
  8596.           (notevery even? '(2 4 6 8))
  8597.              => #f
  8598.  
  8599.  - Function: find-if PRED LST
  8600.      `find-if' searches for the first ELEMENT in LST such that `(PRED
  8601.      ELEMENT)' returns `#t'.  If it finds any such ELEMENT in LST,
  8602.      ELEMENT is returned.  Otherwise, `#f' is returned.
  8603.  
  8604.      Example:
  8605.           (find-if number? '(foo 1 bar 2))
  8606.              => 1
  8607.           
  8608.           (find-if number? '(foo bar baz bang))
  8609.              => #f
  8610.           
  8611.           (find-if symbol? '(1 2 foo bar))
  8612.              => foo
  8613.  
  8614.  - Function: remove ELT LST
  8615.      `remove' removes all occurrences of ELT from LST using `eqv?' to
  8616.      test for equality and returns everything that's left.  N.B.: other
  8617.      implementations (Chez, Scheme->C and T, at least) use `equal?' as
  8618.      the equality test.
  8619.  
  8620.      Example:
  8621.           (remove 1 '(1 2 1 3 1 4 1 5))
  8622.              => (2 3 4 5)
  8623.           
  8624.           (remove 'foo '(bar baz bang))
  8625.              => (bar baz bang)
  8626.  
  8627.  - Function: remove-if PRED LST
  8628.      `remove-if' removes all ELEMENTs from LST where `(PRED ELEMENT)'
  8629.      is `#t' and returns everything that's left.
  8630.  
  8631.      Example:
  8632.           (remove-if number? '(1 2 3 4))
  8633.              => ()
  8634.           
  8635.           (remove-if even? '(1 2 3 4 5 6 7 8))
  8636.              => (1 3 5 7)
  8637.  
  8638.  - Function: remove-if-not PRED LST
  8639.      `remove-if-not' removes all ELEMENTs from LST for which `(PRED
  8640.      ELEMENT)' is `#f' and returns everything that's left.
  8641.  
  8642.      Example:
  8643.           (remove-if-not number? '(foo bar baz))
  8644.              => ()
  8645.           (remove-if-not odd? '(1 2 3 4 5 6 7 8))
  8646.              => (1 3 5 7)
  8647.  
  8648.  - Function: has-duplicates? LST
  8649.      returns `#t' if 2 members of LST are `equal?', `#f' otherwise.
  8650.  
  8651.      Example:
  8652.           (has-duplicates? '(1 2 3 4))
  8653.              => #f
  8654.           
  8655.           (has-duplicates? '(2 4 3 4))
  8656.              => #t
  8657.  
  8658.   The procedure `remove-duplicates' uses `member' (rather than `memv').
  8659.  
  8660.  - Function: remove-duplicates LST
  8661.      returns a copy of LST with its duplicate members removed.
  8662.      Elements are considered duplicate if they are `equal?'.
  8663.  
  8664.      Example:
  8665.           (remove-duplicates '(1 2 3 4))
  8666.              => (4 3 2 1)
  8667.           
  8668.           (remove-duplicates '(2 4 3 4))
  8669.              => (3 4 2)
  8670.  
  8671. 
  8672. File: slib.info,  Node: Lists as sequences,  Next: Destructive list operations,  Prev: Lists as sets,  Up: Common List Functions
  8673.  
  8674. Lists as sequences
  8675. ..................
  8676.  
  8677.  - Function: position OBJ LST
  8678.      `position' returns the 0-based position of OBJ in LST, or `#f' if
  8679.      OBJ does not occur in LST.
  8680.  
  8681.      Example:
  8682.           (position 'foo '(foo bar baz bang))
  8683.              => 0
  8684.           (position 'baz '(foo bar baz bang))
  8685.              => 2
  8686.           (position 'oops '(foo bar baz bang))
  8687.              => #f
  8688.  
  8689.  - Function: reduce P LST
  8690.      `reduce' combines all the elements of a sequence using a binary
  8691.      operation (the combination is left-associative).  For example,
  8692.      using `+', one can add up all the elements.  `reduce' allows you to
  8693.      apply a function which accepts only two arguments to more than 2
  8694.      objects.  Functional programmers usually refer to this as "foldl".
  8695.      `collect:reduce' (*note Collections::.) provides a version of
  8696.      `collect' generalized to collections.
  8697.  
  8698.      Example:
  8699.           (reduce + '(1 2 3 4))
  8700.              => 10
  8701.           (define (bad-sum . l) (reduce + l))
  8702.           (bad-sum 1 2 3 4)
  8703.              == (reduce + (1 2 3 4))
  8704.              == (+ (+ (+ 1 2) 3) 4)
  8705.           => 10
  8706.           (bad-sum)
  8707.              == (reduce + ())
  8708.              => ()
  8709.           (reduce string-append '("hello" "cruel" "world"))
  8710.              == (string-append (string-append "hello" "cruel") "world")
  8711.              => "hellocruelworld"
  8712.           (reduce anything '())
  8713.              => ()
  8714.           (reduce anything '(x))
  8715.              => x
  8716.  
  8717.      What follows is a rather non-standard implementation of `reverse'
  8718.      in terms of `reduce' and a combinator elsewhere called "C".
  8719.  
  8720.           ;;; Contributed by Jussi Piitulainen (jpiitula@ling.helsinki.fi)
  8721.           
  8722.           (define commute
  8723.             (lambda (f)
  8724.               (lambda (x y)
  8725.                 (f y x))))
  8726.           
  8727.           (define reverse
  8728.             (lambda (args)
  8729.               (reduce-init (commute cons) '() args)))
  8730.  
  8731.  - Function: reduce-init P INIT LST
  8732.      `reduce-init' is the same as reduce, except that it implicitly
  8733.      inserts INIT at the start of the list.  `reduce-init' is preferred
  8734.      if you want to handle the null list, the one-element, and lists
  8735.      with two or more elements consistently.  It is common to use the
  8736.      operator's idempotent as the initializer.  Functional programmers
  8737.      usually call this "foldl".
  8738.  
  8739.      Example:
  8740.           (define (sum . l) (reduce-init + 0 l))
  8741.           (sum 1 2 3 4)
  8742.              == (reduce-init + 0 (1 2 3 4))
  8743.              == (+ (+ (+ (+ 0 1) 2) 3) 4)
  8744.              => 10
  8745.           (sum)
  8746.              == (reduce-init + 0 '())
  8747.              => 0
  8748.           
  8749.           (reduce-init string-append "@" '("hello" "cruel" "world"))
  8750.           ==
  8751.           (string-append (string-append (string-append "@" "hello")
  8752.                                          "cruel")
  8753.                          "world")
  8754.           => "@hellocruelworld"
  8755.  
  8756.      Given a differentiation of 2 arguments, `diff', the following will
  8757.      differentiate by any number of variables.
  8758.           (define (diff* exp . vars)
  8759.             (reduce-init diff exp vars))
  8760.  
  8761.      Example:
  8762.           ;;; Real-world example:  Insertion sort using reduce-init.
  8763.           
  8764.           (define (insert l item)
  8765.             (if (null? l)
  8766.                 (list item)
  8767.                 (if (< (car l) item)
  8768.                     (cons (car l) (insert (cdr l) item))
  8769.                     (cons item l))))
  8770.           (define (insertion-sort l) (reduce-init insert '() l))
  8771.           
  8772.           (insertion-sort '(3 1 4 1 5)
  8773.              == (reduce-init insert () (3 1 4 1 5))
  8774.              == (insert (insert (insert (insert (insert () 3) 1) 4) 1) 5)
  8775.              == (insert (insert (insert (insert (3)) 1) 4) 1) 5)
  8776.              == (insert (insert (insert (1 3) 4) 1) 5)
  8777.              == (insert (insert (1 3 4) 1) 5)
  8778.              == (insert (1 1 3 4) 5)
  8779.              => (1 1 3 4 5)
  8780.  
  8781.  - Function: last LST N
  8782.      `last' returns the last N elements of LST.  N must be a
  8783.      non-negative integer.
  8784.  
  8785.      Example:
  8786.           (last '(foo bar baz bang) 2)
  8787.              => (baz bang)
  8788.           (last '(1 2 3) 0)
  8789.              => 0
  8790.  
  8791.  - Function: butlast LST N
  8792.      `butlast' returns all but the last N elements of LST.
  8793.  
  8794.      Example:
  8795.           (butlast '(a b c d) 3)
  8796.              => (a)
  8797.           (butlast '(a b c d) 4)
  8798.              => ()
  8799.  
  8800. `last' and `butlast' split a list into two parts when given identical
  8801. arugments.
  8802.      (last '(a b c d e) 2)
  8803.         => (d e)
  8804.      (butlast '(a b c d e) 2)
  8805.         => (a b c)
  8806.  
  8807.  - Function: nthcdr N LST
  8808.      `nthcdr' takes N `cdr's of LST and returns the result.  Thus
  8809.      `(nthcdr 3 LST)' == `(cdddr LST)'
  8810.  
  8811.      Example:
  8812.           (nthcdr 2 '(a b c d))
  8813.              => (c d)
  8814.           (nthcdr 0 '(a b c d))
  8815.              => (a b c d)
  8816.  
  8817.  - Function: butnthcdr N LST
  8818.      `butnthcdr' returns all but the nthcdr N elements of LST.
  8819.  
  8820.      Example:
  8821.           (butnthcdr 3 '(a b c d))
  8822.              => (a b c)
  8823.           (butnthcdr 4 '(a b c d))
  8824.              => ()
  8825.  
  8826. `nthcdr' and `butnthcdr' split a list into two parts when given
  8827. identical arugments.
  8828.      (nthcdr 2 '(a b c d e))
  8829.         => (c d e)
  8830.      (butnthcdr 2 '(a b c d e))
  8831.         => (a b)
  8832.  
  8833. 
  8834. File: slib.info,  Node: Destructive list operations,  Next: Non-List functions,  Prev: Lists as sequences,  Up: Common List Functions
  8835.  
  8836. Destructive list operations
  8837. ...........................
  8838.  
  8839.   These procedures may mutate the list they operate on, but any such
  8840. mutation is undefined.
  8841.  
  8842.  - Procedure: nconc ARGS
  8843.      `nconc' destructively concatenates its arguments.  (Compare this
  8844.      with `append', which copies arguments rather than destroying them.)
  8845.      Sometimes called `append!' (*note Rev2 Procedures::.).
  8846.  
  8847.      Example:  You want to find the subsets of a set.  Here's the
  8848.      obvious way:
  8849.  
  8850.           (define (subsets set)
  8851.             (if (null? set)
  8852.                 '(())
  8853.                 (append (mapcar (lambda (sub) (cons (car set) sub))
  8854.                                 (subsets (cdr set)))
  8855.                         (subsets (cdr set)))))
  8856.      But that does way more consing than you need.  Instead, you could
  8857.      replace the `append' with `nconc', since you don't have any need
  8858.      for all the intermediate results.
  8859.  
  8860.      Example:
  8861.           (define x '(a b c))
  8862.           (define y '(d e f))
  8863.           (nconc x y)
  8864.              => (a b c d e f)
  8865.           x
  8866.              => (a b c d e f)
  8867.  
  8868.      `nconc' is the same as `append!' in `sc2.scm'.
  8869.  
  8870.  - Procedure: nreverse LST
  8871.      `nreverse' reverses the order of elements in LST by mutating
  8872.      `cdr's of the list.  Sometimes called `reverse!'.
  8873.  
  8874.      Example:
  8875.           (define foo '(a b c))
  8876.           (nreverse foo)
  8877.              => (c b a)
  8878.           foo
  8879.              => (a)
  8880.  
  8881.      Some people have been confused about how to use `nreverse',
  8882.      thinking that it doesn't return a value.  It needs to be pointed
  8883.      out that
  8884.           (set! lst (nreverse lst))
  8885.  
  8886.      is the proper usage, not
  8887.           (nreverse lst)
  8888.      The example should suffice to show why this is the case.
  8889.  
  8890.  - Procedure: delete ELT LST
  8891.  - Procedure: delete-if PRED LST
  8892.  - Procedure: delete-if-not PRED LST
  8893.      Destructive versions of `remove' `remove-if', and `remove-if-not'.
  8894.  
  8895.      Example:
  8896.           (define lst '(foo bar baz bang))
  8897.           (delete 'foo lst)
  8898.              => (bar baz bang)
  8899.           lst
  8900.              => (foo bar baz bang)
  8901.           
  8902.           (define lst '(1 2 3 4 5 6 7 8 9))
  8903.           (delete-if odd? lst)
  8904.              => (2 4 6 8)
  8905.           lst
  8906.              => (1 2 4 6 8)
  8907.  
  8908.      Some people have been confused about how to use `delete',
  8909.      `delete-if', and `delete-if', thinking that they dont' return a
  8910.      value.  It needs to be pointed out that
  8911.           (set! lst (delete el lst))
  8912.  
  8913.      is the proper usage, not
  8914.           (delete el lst)
  8915.      The examples should suffice to show why this is the case.
  8916.  
  8917. 
  8918. File: slib.info,  Node: Non-List functions,  Prev: Destructive list operations,  Up: Common List Functions
  8919.  
  8920. Non-List functions
  8921. ..................
  8922.  
  8923.  - Function: and? . ARGS
  8924.      `and?' checks to see if all its arguments are true.  If they are,
  8925.      `and?' returns `#t', otherwise, `#f'.  (In contrast to `and', this
  8926.      is a function, so all arguments are always evaluated and in an
  8927.      unspecified order.)
  8928.  
  8929.      Example:
  8930.           (and? 1 2 3)
  8931.              => #t
  8932.           (and #f 1 2)
  8933.              => #f
  8934.  
  8935.  - Function: or? . ARGS
  8936.      `or?' checks to see if any of its arguments are true.  If any is
  8937.      true, `or?' returns `#t', and `#f' otherwise.  (To `or' as `and?'
  8938.      is to `and'.)
  8939.  
  8940.      Example:
  8941.           (or? 1 2 #f)
  8942.              => #t
  8943.           (or? #f #f #f)
  8944.              => #f
  8945.  
  8946.  - Function: atom? OBJECT
  8947.      Returns `#t' if OBJECT is not a pair and `#f' if it is pair.
  8948.      (Called `atom' in Common LISP.)
  8949.           (atom? 1)
  8950.              => #t
  8951.           (atom? '(1 2))
  8952.              => #f
  8953.           (atom? #(1 2))   ; dubious!
  8954.              => #t
  8955.  
  8956.  - Function: type-of OBJECT
  8957.      Returns a symbol name for the type of OBJECT.
  8958.  
  8959.  - Function: coerce OBJECT RESULT-TYPE
  8960.      Converts and returns OBJECT of type `char', `number', `string',
  8961.      `symbol', `list', or `vector' to RESULT-TYPE (which must be one of
  8962.      these symbols).
  8963.  
  8964. 
  8965. File: slib.info,  Node: Tree Operations,  Next: Chapter Ordering,  Prev: Common List Functions,  Up: Procedures
  8966.  
  8967. Tree operations
  8968. ---------------
  8969.  
  8970.   `(require 'tree)'
  8971.  
  8972.   These are operations that treat lists a representations of trees.
  8973.  
  8974.  - Function: subst NEW OLD TREE
  8975.  - Function: substq NEW OLD TREE
  8976.  - Function: substv NEW OLD TREE
  8977.      `subst' makes a copy of TREE, substituting NEW for every subtree
  8978.      or leaf of TREE which is `equal?' to OLD and returns a modified
  8979.      tree.  The original TREE is unchanged, but may share parts with
  8980.      the result.
  8981.  
  8982.      `substq' and `substv' are similar, but test against OLD using
  8983.      `eq?' and `eqv?' respectively.
  8984.  
  8985.      Examples:
  8986.           (substq 'tempest 'hurricane '(shakespeare wrote (the hurricane)))
  8987.              => (shakespeare wrote (the tempest))
  8988.           (substq 'foo '() '(shakespeare wrote (twelfth night)))
  8989.              => (shakespeare wrote (twelfth night . foo) . foo)
  8990.           (subst '(a . cons) '(old . pair)
  8991.                  '((old . spice) ((old . shoes) old . pair) (old . pair)))
  8992.              => ((old . spice) ((old . shoes) a . cons) (a . cons))
  8993.  
  8994.  - Function: copy-tree TREE
  8995.      Makes a copy of the nested list structure TREE using new pairs and
  8996.      returns it.  All levels are copied, so that none of the pairs in
  8997.      the tree are `eq?' to the original ones - only the leaves are.
  8998.  
  8999.      Example:
  9000.           (define bar '(bar))
  9001.           (copy-tree (list bar 'foo))
  9002.              => ((bar) foo)
  9003.           (eq? bar (car (copy-tree (list bar 'foo))))
  9004.              => #f
  9005.  
  9006. 
  9007. File: slib.info,  Node: Chapter Ordering,  Next: Sorting,  Prev: Tree Operations,  Up: Procedures
  9008.  
  9009. Chapter Ordering
  9010. ----------------
  9011.  
  9012.   `(require 'chapter-order)'
  9013.  
  9014.   The `chap:' functions deal with strings which are ordered like
  9015. chapter numbers (or letters) in a book.  Each section of the string
  9016. consists of consecutive numeric or consecutive aphabetic characters of
  9017. like case.
  9018.  
  9019.  - Function: chap:string<? STRING1 STRING2
  9020.      Returns #t if the first non-matching run of alphabetic upper-case
  9021.      or the first non-matching run of alphabetic lower-case or the first
  9022.      non-matching run of numeric characters of STRING1 is `string<?'
  9023.      than the corresponding non-matching run of characters of STRING2.
  9024.  
  9025.           (chap:string<? "a.9" "a.10")                    => #t
  9026.           (chap:string<? "4c" "4aa")                      => #t
  9027.           (chap:string<? "Revised^{3.99}" "Revised^{4}")  => #t
  9028.  
  9029.  - Function: chap:string>? STRING1 STRING2
  9030.  - Function: chap:string<=? STRING1 STRING2
  9031.  - Function: chap:string>=? STRING1 STRING2
  9032.      Implement the corresponding chapter-order predicates.
  9033.  
  9034.  - Function: chap:next-string STRING
  9035.      Returns the next string in the *chapter order*.  If STRING has no
  9036.      alphabetic or numeric characters, `(string-append STRING "0")' is
  9037.      returnd.  The argument to chap:next-string will always be
  9038.      `chap:string<?' than the result.
  9039.  
  9040.           (chap:next-string "a.9")                => "a.10"
  9041.           (chap:next-string "4c")                 => "4d"
  9042.           (chap:next-string "4z")                 => "4aa"
  9043.           (chap:next-string "Revised^{4}")        => "Revised^{5}"
  9044.  
  9045. 
  9046. File: slib.info,  Node: Sorting,  Next: Topological Sort,  Prev: Chapter Ordering,  Up: Procedures
  9047.  
  9048. Sorting
  9049. -------
  9050.  
  9051.   `(require 'sort)'
  9052.  
  9053.   Many Scheme systems provide some kind of sorting functions.  They do
  9054. not, however, always provide the *same* sorting functions, and those
  9055. that I have had the opportunity to test provided inefficient ones (a
  9056. common blunder is to use quicksort which does not perform well).
  9057.  
  9058.   Because `sort' and `sort!' are not in the standard, there is very
  9059. little agreement about what these functions look like.  For example,
  9060. Dybvig says that Chez Scheme provides
  9061.      (merge predicate list1 list2)
  9062.      (merge! predicate list1 list2)
  9063.      (sort predicate list)
  9064.      (sort! predicate list)
  9065.  
  9066. while MIT Scheme 7.1, following Common LISP, offers unstable
  9067.      (sort list predicate)
  9068.  
  9069. TI PC Scheme offers
  9070.      (sort! list/vector predicate?)
  9071.  
  9072. and Elk offers
  9073.      (sort list/vector predicate?)
  9074.      (sort! list/vector predicate?)
  9075.  
  9076.   Here is a comprehensive catalogue of the variations I have found.
  9077.  
  9078.   1. Both `sort' and `sort!' may be provided.
  9079.  
  9080.   2. `sort' may be provided without `sort!'.
  9081.  
  9082.   3. `sort!' may be provided without `sort'.
  9083.  
  9084.   4. Neither may be provided.
  9085.  
  9086.   5. The sequence argument may be either a list or a vector.
  9087.  
  9088.   6. The sequence argument may only be a list.
  9089.  
  9090.   7. The sequence argument may only be a vector.
  9091.  
  9092.   8. The comparison function may be expected to behave like `<'.
  9093.  
  9094.   9. The comparison function may be expected to behave like `<='.
  9095.  
  9096.  10. The interface may be `(sort predicate? sequence)'.
  9097.  
  9098.  11. The interface may be `(sort sequence predicate?)'.
  9099.  
  9100.  12. The interface may be `(sort sequence &optional (predicate? <))'.
  9101.  
  9102.  13. The sort may be stable.
  9103.  
  9104.  14. The sort may be unstable.
  9105.  
  9106.   All of this variation really does not help anybody.  A nice simple
  9107. merge sort is both stable and fast (quite a lot faster than *quick*
  9108. sort).
  9109.  
  9110.   I am providing this source code with no restrictions at all on its use
  9111. (but please retain D.H.D.Warren's credit for the original idea).  You
  9112. may have to rename some of these functions in order to use them in a
  9113. system which already provides incompatible or inferior sorts.  For each
  9114. of the functions, only the top-level define needs to be edited to do
  9115. that.
  9116.  
  9117.   I could have given these functions names which would not clash with
  9118. any Scheme that I know of, but I would like to encourage implementors to
  9119. converge on a single interface, and this may serve as a hint.  The
  9120. argument order for all functions has been chosen to be as close to
  9121. Common LISP as made sense, in order to avoid NIH-itis.
  9122.  
  9123.   Each of the five functions has a required *last* parameter which is a
  9124. comparison function.  A comparison function `f' is a function of 2
  9125. arguments which acts like `<'.  For example,
  9126.  
  9127.      (not (f x x))
  9128.      (and (f x y) (f y z)) == (f x z)
  9129.  
  9130.   The standard functions `<', `>', `char<?', `char>?', `char-ci<?',
  9131. `char-ci>?', `string<?', `string>?', `string-ci<?', and `string-ci>?'
  9132. are suitable for use as comparison functions.  Think of `(less? x y)'
  9133. as saying when `x' must *not* precede `y'.
  9134.  
  9135.  - Function: sorted? SEQUENCE LESS?
  9136.      Returns `#t' when the sequence argument is in non-decreasing order
  9137.      according to LESS? (that is, there is no adjacent pair `... x y
  9138.      ...' for which `(less? y x)').
  9139.  
  9140.      Returns `#f' when the sequence contains at least one out-of-order
  9141.      pair.  It is an error if the sequence is neither a list nor a
  9142.      vector.
  9143.  
  9144.  - Function: merge LIST1 LIST2 LESS?
  9145.      This merges two lists, producing a completely new list as result.
  9146.      I gave serious consideration to producing a Common-LISP-compatible
  9147.      version.  However, Common LISP's `sort' is our `sort!' (well, in
  9148.      fact Common LISP's `stable-sort' is our `sort!', merge sort is
  9149.      *fast* as well as stable!) so adapting CL code to Scheme takes a
  9150.      bit of work anyway.  I did, however, appeal to CL to determine the
  9151.      *order* of the arguments.
  9152.  
  9153.  - Procedure: merge! LIST1 LIST2 LESS?
  9154.      Merges two lists, re-using the pairs of LIST1 and LIST2 to build
  9155.      the result.  If the code is compiled, and LESS? constructs no new
  9156.      pairs, no pairs at all will be allocated.  The first pair of the
  9157.      result will be either the first pair of LIST1 or the first pair of
  9158.      LIST2, but you can't predict which.
  9159.  
  9160.      The code of `merge' and `merge!' could have been quite a bit
  9161.      simpler, but they have been coded to reduce the amount of work
  9162.      done per iteration.  (For example, we only have one `null?' test
  9163.      per iteration.)
  9164.  
  9165.  - Function: sort SEQUENCE LESS?
  9166.      Accepts either a list or a vector, and returns a new sequence
  9167.      which is sorted.  The new sequence is the same type as the input.
  9168.      Always `(sorted? (sort sequence less?) less?)'.  The original
  9169.      sequence is not altered in any way.  The new sequence shares its
  9170.      *elements* with the old one; no elements are copied.
  9171.  
  9172.  - Procedure: sort! SEQUENCE LESS?
  9173.      Returns its sorted result in the original boxes.  If the original
  9174.      sequence is a list, no new storage is allocated at all.  If the
  9175.      original sequence is a vector, the sorted elements are put back in
  9176.      the same vector.
  9177.  
  9178.      Some people have been confused about how to use `sort!', thinking
  9179.      that it doesn't return a value.  It needs to be pointed out that
  9180.           (set! slist (sort! slist <))
  9181.  
  9182.      is the proper usage, not
  9183.           (sort! slist <)
  9184.  
  9185.   Note that these functions do *not* accept a CL-style `:key' argument.
  9186. A simple device for obtaining the same expressiveness is to define
  9187.      (define (keyed less? key)
  9188.        (lambda (x y) (less? (key x) (key y))))
  9189.  
  9190. and then, when you would have written
  9191.      (sort a-sequence #'my-less :key #'my-key)
  9192.  
  9193. in Common LISP, just write
  9194.      (sort! a-sequence (keyed my-less? my-key))
  9195.  
  9196. in Scheme.
  9197.  
  9198. 
  9199. File: slib.info,  Node: Topological Sort,  Next: String-Case,  Prev: Sorting,  Up: Procedures
  9200.  
  9201. Topological Sort
  9202. ----------------
  9203.  
  9204.   `(require 'topological-sort)' or `(require 'tsort)'
  9205.  
  9206. The algorithm is inspired by Cormen, Leiserson and Rivest (1990)
  9207. `Introduction to Algorithms', chapter 23.
  9208.  
  9209.  - Function: tsort DAG PRED
  9210.  - Function: topological-sort DAG PRED
  9211.      where
  9212.     DAG
  9213.           is a list of sublists.  The car of each sublist is a vertex.
  9214.           The cdr is the adjacency list of that vertex, i.e. a list of
  9215.           all vertices to which there exists an edge from the car
  9216.           vertex.
  9217.  
  9218.     PRED
  9219.           is one of `eq?', `eqv?', `equal?', `=', `char=?',
  9220.           `char-ci=?', `string=?', or `string-ci=?'.
  9221.  
  9222.      Sort the directed acyclic graph DAG so that for every edge from
  9223.      vertex U to V, U will come before V in the resulting list of
  9224.      vertices.
  9225.  
  9226.      Time complexity: O (|V| + |E|)
  9227.  
  9228.      Example (from Cormen):
  9229.           Prof. Bumstead topologically sorts his clothing when getting
  9230.           dressed.  The first argument to `tsort' describes which
  9231.           garments he needs to put on before others.  (For example,
  9232.           Prof Bumstead needs to put on his shirt before he puts on his
  9233.           tie or his belt.)  `tsort' gives the correct order of
  9234.           dressing:
  9235.  
  9236.           (require 'tsort)
  9237.           (tsort '((shirt tie belt)
  9238.                    (tie jacket)
  9239.                    (belt jacket)
  9240.                    (watch)
  9241.                    (pants shoes belt)
  9242.                    (undershorts pants shoes)
  9243.                    (socks shoes))
  9244.                  eq?)
  9245.           =>
  9246.           (socks undershorts pants shoes watch shirt belt tie jacket)
  9247.  
  9248. 
  9249. File: slib.info,  Node: String-Case,  Next: String Ports,  Prev: Topological Sort,  Up: Procedures
  9250.  
  9251. String-Case
  9252. -----------
  9253.  
  9254.   `(require 'string-case)'
  9255.  
  9256.  - Procedure: string-upcase STR
  9257.  - Procedure: string-downcase STR
  9258.  - Procedure: string-capitalize STR
  9259.      The obvious string conversion routines.  These are non-destructive.
  9260.  
  9261.  - Function: string-upcase! STR
  9262.  - Function: string-downcase! STR
  9263.  - Function: string-captialize! STR
  9264.      The destructive versions of the functions above.
  9265.  
  9266.  - Function: string-ci->symbol STR
  9267.      Converts string STR to a symbol having the same case as if the
  9268.      symbol had been `read'.
  9269.  
  9270. 
  9271. File: slib.info,  Node: String Ports,  Next: String Search,  Prev: String-Case,  Up: Procedures
  9272.  
  9273. String Ports
  9274. ------------
  9275.  
  9276.   `(require 'string-port)'
  9277.  
  9278.  - Procedure: call-with-output-string PROC
  9279.      PROC must be a procedure of one argument.  This procedure calls
  9280.      PROC with one argument: a (newly created) output port.  When the
  9281.      function returns, the string composed of the characters written
  9282.      into the port is returned.
  9283.  
  9284.  - Procedure: call-with-input-string STRING PROC
  9285.      PROC must be a procedure of one argument.  This procedure calls
  9286.      PROC with one argument: an (newly created) input port from which
  9287.      STRING's contents may be read.  When PROC returns, the port is
  9288.      closed and the value yielded by the procedure PROC is returned.
  9289.  
  9290. 
  9291. File: slib.info,  Node: String Search,  Next: Line I/O,  Prev: String Ports,  Up: Procedures
  9292.  
  9293. String Search
  9294. -------------
  9295.  
  9296.   `(require 'string-search)'
  9297.  
  9298.  - Procedure: string-index STRING CHAR
  9299.  - Procedure: string-index-ci STRING CHAR
  9300.      Returns the index of the first occurence of CHAR within STRING, or
  9301.      `#f' if the STRING does not contain a character CHAR.
  9302.  
  9303.  - Procedure: string-reverse-index STRING CHAR
  9304.  - Procedure: string-reverse-index-ci STRING CHAR
  9305.      Returns the index of the last occurence of CHAR within STRING, or
  9306.      `#f' if the STRING does not contain a character CHAR.
  9307.  
  9308.  - procedure: substring? PATTERN STRING
  9309.  - procedure: substring-ci? PATTERN STRING
  9310.      Searches STRING to see if some substring of STRING is equal to
  9311.      PATTERN.  `substring?' returns the index of the first character of
  9312.      the first substring of STRING that is equal to PATTERN; or `#f' if
  9313.      STRING does not contain PATTERN.
  9314.  
  9315.           (substring? "rat" "pirate") =>  2
  9316.           (substring? "rat" "outrage") =>  #f
  9317.           (substring? "" any-string) =>  0
  9318.  
  9319.  - Procedure: find-string-from-port? STR IN-PORT MAX-NO-CHARS
  9320.      Looks for a string STR within the first MAX-NO-CHARS chars of the
  9321.      input port IN-PORT.
  9322.  
  9323.  - Procedure: find-string-from-port? STR IN-PORT
  9324.      When called with two arguments, the search span is limited by the
  9325.      end of the input stream.
  9326.  
  9327.  - Procedure: find-string-from-port? STR IN-PORT CHAR
  9328.      Searches up to the first occurrence of character CHAR in STR.
  9329.  
  9330.  - Procedure: find-string-from-port? STR IN-PORT PROC
  9331.      Searches up to the first occurrence of the procedure PROC
  9332.      returning non-false when called with a character (from IN-PORT)
  9333.      argument.
  9334.  
  9335.      When the STR is found, `find-string-from-port?' returns the number
  9336.      of characters it has read from the port, and the port is set to
  9337.      read the first char after that (that is, after the STR) The
  9338.      function returns `#f' when the STR isn't found.
  9339.  
  9340.      `find-string-from-port?' reads the port *strictly* sequentially,
  9341.      and does not perform any buffering.  So `find-string-from-port?'
  9342.      can be used even if the IN-PORT is open to a pipe or other
  9343.      communication channel.
  9344.  
  9345.  - Function: string-subst TXT OLD1 NEW1 ...
  9346.      Returns a copy of string TXT with all occurrences of string OLD1
  9347.      in TXT replaced with NEW1, OLD2 replaced with NEW2 ....
  9348.  
  9349. 
  9350. File: slib.info,  Node: Line I/O,  Next: Multi-Processing,  Prev: String Search,  Up: Procedures
  9351.  
  9352. Line I/O
  9353. --------
  9354.  
  9355.   `(require 'line-i/o)'
  9356.  
  9357.  - Function: read-line
  9358.  - Function: read-line PORT
  9359.      Returns a string of the characters up to, but not including a
  9360.      newline or end of file, updating PORT to point to the character
  9361.      following the newline.  If no characters are available, an end of
  9362.      file object is returned.  The PORT argument may be omitted, in
  9363.      which case it defaults to the value returned by
  9364.      `current-input-port'.
  9365.  
  9366.  - Function: read-line! STRING
  9367.  - Function: read-line! STRING PORT
  9368.      Fills STRING with characters up to, but not including a newline or
  9369.      end of file, updating the PORT to point to the last character read
  9370.      or following the newline if it was read.  If no characters are
  9371.      available, an end of file object is returned.  If a newline or end
  9372.      of file was found, the number of characters read is returned.
  9373.      Otherwise, `#f' is returned.  The PORT argument may be omitted, in
  9374.      which case it defaults to the value returned by
  9375.      `current-input-port'.
  9376.  
  9377.  - Function: write-line STRING
  9378.  - Function: write-line STRING PORT
  9379.      Writes STRING followed by a newline to the given PORT and returns
  9380.      an unspecified value.  The PORT argument may be omitted, in which        |
  9381.      case it defaults to the value returned by `current-input-port'.
  9382.  
  9383.  - Function: display-file PATH
  9384.  - Function: display-file PATH PORT
  9385.      Displays the contents of the file named by PATH to PORT.  The PORT
  9386.      argument may be ommited, in which case it defaults to the value
  9387.      returned by `current-output-port'.
  9388.  
  9389. 
  9390. File: slib.info,  Node: Multi-Processing,  Prev: Line I/O,  Up: Procedures
  9391.  
  9392. Multi-Processing
  9393. ----------------
  9394.  
  9395.   `(require 'process)'
  9396.  
  9397.   This module implements asynchronous (non-polled) time-sliced
  9398. multi-processing in the SCM Scheme implementation using procedures
  9399. `alarm' and `alarm-interrupt'.  Until this is ported to another
  9400. implementation, consider it an example of writing schedulers in Scheme.
  9401.  
  9402.  - Procedure: add-process! PROC
  9403.      Adds proc, which must be a procedure (or continuation) capable of
  9404.      accepting accepting one argument, to the `process:queue'.  The
  9405.      value returned is unspecified.  The argument to PROC should be
  9406.      ignored.  If PROC returns, the process is killed.
  9407.  
  9408.  - Procedure: process:schedule!
  9409.      Saves the current process on `process:queue' and runs the next
  9410.      process from `process:queue'.  The value returned is unspecified.
  9411.  
  9412.  - Procedure: kill-process!
  9413.      Kills the current process and runs the next process from
  9414.      `process:queue'.  If there are no more processes on
  9415.      `process:queue', `(slib:exit)' is called (*note System::.).
  9416.  
  9417. 
  9418. File: slib.info,  Node: Standards Support,  Next: Session Support,  Prev: Procedures,  Up: Other Packages
  9419.  
  9420. Standards Support
  9421. =================
  9422.  
  9423. * Menu:
  9424.  
  9425. * With-File::                   'with-file
  9426. * Transcripts::                 'transcript
  9427. * Rev2 Procedures::             'rev2-procedures
  9428. * Rev4 Optional Procedures::    'rev4-optional-procedures
  9429. * Multi-argument / and -::      'multiarg/and-
  9430. * Multi-argument Apply::        'multiarg-apply
  9431. * Rationalize::                 'rationalize
  9432. * Promises::                    'promise
  9433. * Dynamic-Wind::                'dynamic-wind
  9434. * Eval::                        'eval
  9435. * Values::                      'values
  9436.  
  9437. 
  9438. File: slib.info,  Node: With-File,  Next: Transcripts,  Prev: Standards Support,  Up: Standards Support
  9439.  
  9440. With-File
  9441. ---------
  9442.  
  9443.   `(require 'with-file)'
  9444.  
  9445.  - Function: with-input-from-file FILE THUNK
  9446.  - Function: with-output-to-file FILE THUNK
  9447.      Description found in R4RS.
  9448.  
  9449. 
  9450. File: slib.info,  Node: Transcripts,  Next: Rev2 Procedures,  Prev: With-File,  Up: Standards Support
  9451.  
  9452. Transcripts
  9453. -----------
  9454.  
  9455.   `(require 'transcript)'
  9456.  
  9457.  - Function: transcript-on FILENAME
  9458.  - Function: transcript-off FILENAME
  9459.      Redefines `read-char', `read', `write-char', `write', `display',
  9460.      and `newline'.
  9461.  
  9462. 
  9463. File: slib.info,  Node: Rev2 Procedures,  Next: Rev4 Optional Procedures,  Prev: Transcripts,  Up: Standards Support
  9464.  
  9465. Rev2 Procedures
  9466. ---------------
  9467.  
  9468.   `(require 'rev2-procedures)'
  9469.  
  9470.   The procedures below were specified in the `Revised^2 Report on
  9471. Scheme'.  *N.B.*: The symbols `1+' and `-1+' are not `R4RS' syntax.
  9472. Scheme->C, for instance, barfs on this module.
  9473.  
  9474.  - Procedure: substring-move-left! STRING1 START1 END1 STRING2 START2
  9475.  - Procedure: substring-move-right! STRING1 START1 END1 STRING2 START2
  9476.      STRING1 and STRING2 must be a strings, and START1, START2 and END1
  9477.      must be exact integers satisfying
  9478.  
  9479.           0 <= START1 <= END1 <= (string-length STRING1)
  9480.           0 <= START2 <= END1 - START1 + START2 <= (string-length STRING2)
  9481.  
  9482.      `substring-move-left!' and `substring-move-right!' store
  9483.      characters of STRING1 beginning with index START1 (inclusive) and
  9484.      ending with index END1 (exclusive) into STRING2 beginning with
  9485.      index START2 (inclusive).
  9486.  
  9487.      `substring-move-left!' stores characters in time order of
  9488.      increasing indices.  `substring-move-right!' stores characters in
  9489.      time order of increasing indeces.
  9490.  
  9491.  - Procedure: substring-fill! STRING START END CHAR
  9492.      Fills the elements START-END of STRING with the character CHAR.
  9493.  
  9494.  - Function: string-null? STR
  9495.      == `(= 0 (string-length STR))'
  9496.  
  9497.  - Procedure: append! . PAIRS
  9498.      Destructively appends its arguments.  Equivalent to `nconc'.
  9499.  
  9500.  - Function: 1+ N
  9501.      Adds 1 to N.
  9502.  
  9503.  - Function: -1+ N
  9504.      Subtracts 1 from N.
  9505.  
  9506.  - Function: <?
  9507.  - Function: <=?
  9508.  - Function: =?
  9509.  - Function: >?
  9510.  - Function: >=?
  9511.      These are equivalent to the procedures of the same name but
  9512.      without the trailing `?'.
  9513.  
  9514. 
  9515. File: slib.info,  Node: Rev4 Optional Procedures,  Next: Multi-argument / and -,  Prev: Rev2 Procedures,  Up: Standards Support
  9516.  
  9517. Rev4 Optional Procedures
  9518. ------------------------
  9519.  
  9520.   `(require 'rev4-optional-procedures)'
  9521.  
  9522.   For the specification of these optional procedures, *Note Standard
  9523. procedures: (r4rs)Standard procedures.
  9524.  
  9525.  - Function: list-tail L P
  9526.  
  9527.  - Function: string->list S
  9528.  
  9529.  - Function: list->string L
  9530.  
  9531.  - Function: string-copy
  9532.  
  9533.  - Procedure: string-fill! S OBJ
  9534.  
  9535.  - Function: list->vector L
  9536.  
  9537.  - Function: vector->list S
  9538.  
  9539.  - Procedure: vector-fill! S OBJ
  9540.  
  9541. 
  9542. File: slib.info,  Node: Multi-argument / and -,  Next: Multi-argument Apply,  Prev: Rev4 Optional Procedures,  Up: Standards Support
  9543.  
  9544. Multi-argument / and -
  9545. ----------------------
  9546.  
  9547.   `(require 'mutliarg/and-)'
  9548.  
  9549.   For the specification of these optional forms, *Note Numerical
  9550. operations: (r4rs)Numerical operations.  The `two-arg:'* forms are only
  9551. defined if the implementation does not support the many-argument forms.
  9552.  
  9553.  - Function: two-arg:/ N1 N2
  9554.      The original two-argument version of `/'.
  9555.  
  9556.  - Function: / DIVIDENT . DIVISORS
  9557.  
  9558.  - Function: two-arg:- N1 N2
  9559.      The original two-argument version of `-'.
  9560.  
  9561.  - Function: - MINUEND . SUBTRAHENDS
  9562.  
  9563. 
  9564. File: slib.info,  Node: Multi-argument Apply,  Next: Rationalize,  Prev: Multi-argument / and -,  Up: Standards Support
  9565.  
  9566. Multi-argument Apply
  9567. --------------------
  9568.  
  9569.   `(require 'multiarg-apply)'
  9570.  
  9571. For the specification of this optional form, *Note Control features:
  9572. (r4rs)Control features.
  9573.  
  9574.  - Function: two-arg:apply PROC L
  9575.      The implementation's native `apply'.  Only defined for
  9576.      implementations which don't support the many-argument version.
  9577.  
  9578.  - Function: apply PROC . ARGS
  9579.  
  9580. 
  9581. File: slib.info,  Node: Rationalize,  Next: Promises,  Prev: Multi-argument Apply,  Up: Standards Support
  9582.  
  9583. Rationalize
  9584. -----------
  9585.  
  9586.   `(require 'rationalize)'
  9587.  
  9588.   The procedure "rationalize" is interesting because most programming         |
  9589. languages do not provide anything analogous to it.  Thanks to Alan            |
  9590. Bawden for contributing this algorithm.                                       |
  9591.                                                                               |
  9592.  - Function: rationalize X Y                                                  |
  9593.      Computes the correct result for exact arguments (provided the            |
  9594.      implementation supports exact rational numbers of unlimited              |
  9595.      precision); and produces a reasonable answer for inexact arguments       |
  9596.      when inexact arithmetic is implemented using floating-point.             |
  9597.                                                                               |
  9598.   `Rationalize' has limited use in implementations lacking exact              |
  9599. (non-integer) rational numbers.  The following procedures return a list       |
  9600. of the numerator and denominator.                                             |
  9601.                                                                               |
  9602.  - Function: find-ratio X Y                                                   |
  9603.      `find-ratio' returns the list of the *simplest* numerator and            |
  9604.      denominator whose quotient differs from X by no more than Y.             |
  9605.                                                                               |
  9606.      (find-ratio 3/97 .0001)             ==> (3 97)                           |
  9607.      (find-ratio 3/97 .001)              ==> (1 32)                           |
  9608.                                                                               |
  9609.  - Function: find-ratio-between X Y                                           |
  9610.      `find-ratio-between' returns the list of the *simplest* numerator        |
  9611.      and denominator between X and Y.                                         |
  9612.  
  9613.      (find-ratio-between 2/7 3/5)        ==> (1 2)                            |
  9614.      (find-ratio-between -3/5 -2/7)      ==> (-1 2)                           |
  9615.  
  9616. 
  9617. File: slib.info,  Node: Promises,  Next: Dynamic-Wind,  Prev: Rationalize,  Up: Standards Support
  9618.  
  9619. Promises
  9620. --------
  9621.  
  9622.   `(require 'promise)'
  9623.  
  9624.  - Function: make-promise PROC
  9625.  
  9626.   Change occurrences of `(delay EXPRESSION)' to `(make-promise (lambda
  9627. () EXPRESSION))' and `(define force promise:force)' to implement
  9628. promises if your implementation doesn't support them (*note Control
  9629. features: (r4rs)Control features.).
  9630.  
  9631. 
  9632. File: slib.info,  Node: Dynamic-Wind,  Next: Eval,  Prev: Promises,  Up: Standards Support
  9633.  
  9634. Dynamic-Wind
  9635. ------------
  9636.  
  9637.   `(require 'dynamic-wind)'
  9638.  
  9639.   This facility is a generalization of Common LISP `unwind-protect',
  9640. designed to take into account the fact that continuations produced by
  9641. `call-with-current-continuation' may be reentered.
  9642.  
  9643.  - Procedure: dynamic-wind THUNK1 THUNK2 THUNK3
  9644.      The arguments THUNK1, THUNK2, and THUNK3 must all be procedures of
  9645.      no arguments (thunks).
  9646.  
  9647.      `dynamic-wind' calls THUNK1, THUNK2, and then THUNK3.  The value
  9648.      returned by THUNK2 is returned as the result of `dynamic-wind'.
  9649.      THUNK3 is also called just before control leaves the dynamic
  9650.      context of THUNK2 by calling a continuation created outside that
  9651.      context.  Furthermore, THUNK1 is called before reentering the
  9652.      dynamic context of THUNK2 by calling a continuation created inside
  9653.      that context.  (Control is inside the context of THUNK2 if THUNK2
  9654.      is on the current return stack).
  9655.  
  9656.      *Warning:* There is no provision for dealing with errors or
  9657.      interrupts.  If an error or interrupt occurs while using
  9658.      `dynamic-wind', the dynamic environment will be that in effect at
  9659.      the time of the error or interrupt.
  9660.  
  9661. 
  9662. File: slib.info,  Node: Eval,  Next: Values,  Prev: Dynamic-Wind,  Up: Standards Support
  9663.  
  9664. Eval
  9665. ----
  9666.  
  9667.   `(require 'eval)'
  9668.  
  9669.  - Function: eval EXPRESSION ENVIRONMENT-SPECIFIER
  9670.      Evaluates EXPRESSION in the specified environment and returns its
  9671.      value.  EXPRESSION must be a valid Scheme expression represented
  9672.      as data, and ENVIRONMENT-SPECIFIER must be a value returned by one
  9673.      of the three procedures described below.  Implementations may
  9674.      extend `eval' to allow non-expression programs (definitions) as
  9675.      the first argument and to allow other values as environments, with
  9676.      the restriction that `eval' is not allowed to create new bindings
  9677.      in the environments associated with `null-environment' or
  9678.      `scheme-report-environment'.
  9679.  
  9680.           (eval '(* 7 3) (scheme-report-environment 5))
  9681.                                                              =>  21
  9682.           
  9683.           (let ((f (eval '(lambda (f x) (f x x))
  9684.                          (null-environment))))
  9685.             (f + 10))
  9686.                                                              =>  20
  9687.  
  9688.  - Function: scheme-report-environment VERSION
  9689.  - Function: null-environment VERSION
  9690.  - Function: null-environment
  9691.      VERSION must be an exact non-negative integer N corresponding to a
  9692.      version of one of the Revised^N Reports on Scheme.
  9693.      `Scheme-report-environment' returns a specifier for an environment
  9694.      that contains the set of bindings specified in the corresponding
  9695.      report that the implementation supports.  `Null-environment'
  9696.      returns a specifier for an environment that contains only the
  9697.      (syntactic) bindings for all the syntactic keywords defined in the
  9698.      given version of the report.
  9699.  
  9700.      Not all versions may be available in all implementations at all
  9701.      times.  However, an implementation that conforms to version N of
  9702.      the Revised^N Reports on Scheme must accept version N.  An error
  9703.      is signalled if the specified version is not available.
  9704.  
  9705.      The effect of assigning (through the use of `eval') a variable
  9706.      bound in a `scheme-report-environment' (for example `car') is
  9707.      unspecified. Thus the environments specified by
  9708.      `scheme-report-environment' may be immutable.
  9709.  
  9710.  
  9711.  - Function: interaction-environment
  9712.      This optional procedure returns a specifier for the environment
  9713.      that contains implementation-defined bindings, typically a
  9714.      superset of those listed in the report.  The intent is that this
  9715.      procedure will return the environment in which the implementation
  9716.      would evaluate expressions dynamically typed by the user.
  9717.  
  9718. Here are some more `eval' examples:
  9719.  
  9720.      (require 'eval)
  9721.      => #<unspecified>
  9722.      (define car 'volvo)
  9723.      => #<unspecified>
  9724.      car
  9725.      => volvo
  9726.      (eval 'car (interaction-environment))
  9727.      => volvo
  9728.      (eval 'car (scheme-report-environment 5))
  9729.      => #<primitive-procedure car>
  9730.      (eval '(eval 'car (interaction-environment))
  9731.            (scheme-report-environment 5))
  9732.      => volvo
  9733.      (eval '(eval '(set! car 'buick) (interaction-environment))
  9734.            (scheme-report-environment 5))
  9735.      => #<unspecified>
  9736.      car
  9737.      => buick
  9738.      (eval 'car (scheme-report-environment 5))
  9739.      => #<primitive-procedure car>
  9740.      (eval '(eval 'car (interaction-environment))
  9741.            (scheme-report-environment 5))
  9742.      => buick
  9743.  
  9744. 
  9745. File: slib.info,  Node: Values,  Prev: Eval,  Up: Standards Support
  9746.  
  9747. Values
  9748. ------
  9749.  
  9750.   `(require 'values)'
  9751.  
  9752.  - Function: values OBJ ...
  9753.      `values' takes any number of arguments, and passes (returns) them
  9754.      to its continuation.
  9755.  
  9756.  - Function: call-with-values THUNK PROC
  9757.      THUNK must be a procedure of no arguments, and PROC must be a
  9758.      procedure.  `call-with-values' calls THUNK with a continuation
  9759.      that, when passed some values, calls PROC with those values as
  9760.      arguments.
  9761.  
  9762.      Except for continuations created by the `call-with-values'
  9763.      procedure, all continuations take exactly one value, as now; the
  9764.      effect of passing no value or more than one value to continuations
  9765.      that were not created by the `call-with-values' procedure is
  9766.      unspecified.
  9767.  
  9768. 
  9769. File: slib.info,  Node: Session Support,  Next: Extra-SLIB Packages,  Prev: Standards Support,  Up: Other Packages
  9770.  
  9771. Session Support
  9772. ===============
  9773.  
  9774. * Menu:
  9775.  
  9776. * Repl::                        Macros at top-level
  9777. * Quick Print::                 Loop-safe Output
  9778. * Debug::                       To err is human ...
  9779. * Breakpoints::                 Pause execution
  9780. * Trace::                       'trace
  9781. * System Interface::            'system, 'getenv, and 'net-clients
  9782.  
  9783. 
  9784. File: slib.info,  Node: Repl,  Next: Quick Print,  Prev: Session Support,  Up: Session Support
  9785.  
  9786. Repl
  9787. ----
  9788.  
  9789.   `(require 'repl)'
  9790.  
  9791.   Here is a read-eval-print-loop which, given an eval, evaluates forms.
  9792.  
  9793.  - Procedure: repl:top-level REPL:EVAL
  9794.      `read's, `repl:eval's and `write's expressions from
  9795.      `(current-input-port)' to `(current-output-port)' until an
  9796.      end-of-file is encountered.  `load', `slib:eval', `slib:error',
  9797.      and `repl:quit' dynamically bound during `repl:top-level'.
  9798.  
  9799.  - Procedure: repl:quit
  9800.      Exits from the invocation of `repl:top-level'.
  9801.  
  9802.   The `repl:' procedures establish, as much as is possible to do
  9803. portably, a top level environment supporting macros.  `repl:top-level'
  9804. uses `dynamic-wind' to catch error conditions and interrupts.  If your
  9805. implementation supports this you are all set.
  9806.  
  9807.   Otherwise, if there is some way your implementation can catch error
  9808. conditions and interrupts, then have them call `slib:error'.  It will
  9809. display its arguments and reenter `repl:top-level'.  `slib:error'
  9810. dynamically bound by `repl:top-level'.
  9811.  
  9812.   To have your top level loop always use macros, add any interrupt
  9813. catching lines and the following lines to your Scheme init file:
  9814.      (require 'macro)
  9815.      (require 'repl)
  9816.      (repl:top-level macro:eval)
  9817.  
  9818. 
  9819. File: slib.info,  Node: Quick Print,  Next: Debug,  Prev: Repl,  Up: Session Support
  9820.  
  9821. Quick Print
  9822. -----------
  9823.  
  9824.   `(require 'qp)'
  9825.  
  9826. When displaying error messages and warnings, it is paramount that the
  9827. output generated for circular lists and large data structures be
  9828. limited.  This section supplies a procedure to do this.  It could be
  9829. much improved.
  9830.  
  9831.      Notice that the neccessity for truncating output eliminates
  9832.      Common-Lisp's *Note Format:: from consideration; even when
  9833.      variables `*print-level*' and `*print-level*' are set, huge
  9834.      strings and bit-vectors are *not* limited.
  9835.  
  9836.  - Procedure: qp ARG1 ...
  9837.  - Procedure: qpn ARG1 ...
  9838.  - Procedure: qpr ARG1 ...
  9839.      `qp' writes its arguments, separated by spaces, to
  9840.      `(current-output-port)'.  `qp' compresses printing by substituting
  9841.      `...' for substructure it does not have sufficient room to print.
  9842.      `qpn' is like `qp' but outputs a newline before returning.  `qpr'
  9843.      is like `qpn' except that it returns its last argument.
  9844.  
  9845.  - Variable: *qp-width*
  9846.      `*qp-width*' is the largest number of characters that `qp' should
  9847.      use.
  9848.  
  9849. 
  9850. File: slib.info,  Node: Debug,  Next: Breakpoints,  Prev: Quick Print,  Up: Session Support
  9851.  
  9852. Debug
  9853. -----
  9854.  
  9855.   `(require 'debug)'
  9856.  
  9857. Requiring `debug' automatically requires `trace' and `break'.
  9858.  
  9859. An application with its own datatypes may want to substitute its own
  9860. printer for `qp'.  This example shows how to do this:
  9861.  
  9862.      (define qpn (lambda args) ...)
  9863.      (provide 'qp)
  9864.      (require 'debug)
  9865.  
  9866.  - Procedure: trace-all FILE ...                                              |
  9867.      Traces (*note Trace::.) all procedures `define'd at top-level in
  9868.      `file' ....                                                              |
  9869.                                                                               |
  9870.  - Procedure: track-all FILE ...                                              |
  9871.      Tracks (*note Trace::.) all procedures `define'd at top-level in         |
  9872.      `file' ....                                                              |
  9873.                                                                               |
  9874.  - Procedure: stack-all FILE ...                                              |
  9875.      Stacks (*note Trace::.) all procedures `define'd at top-level in         |
  9876.      `file' ....                                                              |
  9877.  
  9878.  - Procedure: break-all FILE ...                                              |
  9879.      Breakpoints (*note Breakpoints::.) all procedures `define'd at
  9880.      top-level in `file' ....                                                 |
  9881.  
  9882. 
  9883. File: slib.info,  Node: Breakpoints,  Next: Trace,  Prev: Debug,  Up: Session Support
  9884.  
  9885. Breakpoints
  9886. -----------
  9887.  
  9888.   `(require 'break)'
  9889.  
  9890.  - Function: init-debug
  9891.      If your Scheme implementation does not support `break' or `abort',
  9892.      a message will appear when you `(require 'break)' or `(require
  9893.      'debug)' telling you to type `(init-debug)'.  This is in order to
  9894.      establish a top-level continuation.  Typing `(init-debug)' at top
  9895.      level sets up a continuation for `break'.
  9896.  
  9897.  - Function: breakpoint ARG1 ...
  9898.      Returns from the top level continuation and pushes the
  9899.      continuation from which it was called on a continuation stack.
  9900.  
  9901.  - Function: continue
  9902.      Pops the topmost continuation off of the continuation stack and
  9903.      returns an unspecified value to it.
  9904.  
  9905.  - Function: continue ARG1 ...
  9906.      Pops the topmost continuation off of the continuation stack and
  9907.      returns ARG1 ... to it.
  9908.  
  9909.  - Macro: break PROC1 ...
  9910.      Redefines the top-level named procedures given as arguments so that
  9911.      `breakpoint' is called before calling PROC1 ....
  9912.  
  9913.  - Macro: break
  9914.      With no arguments, makes sure that all the currently broken
  9915.      identifiers are broken (even if those identifiers have been
  9916.      redefined) and returns a list of the broken identifiers.
  9917.  
  9918.  - Macro: unbreak PROC1 ...
  9919.      Turns breakpoints off for its arguments.
  9920.  
  9921.  - Macro: unbreak
  9922.      With no arguments, unbreaks all currently broken identifiers and
  9923.      returns a list of these formerly broken identifiers.
  9924.  
  9925.   These are *procedures* for breaking.  If defmacros are not natively         |
  9926. supported by your implementation, these might be more convenient to use.      |
  9927.  
  9928.  - Function: breakf PROC
  9929.  - Function: breakf PROC NAME                                                 |
  9930.      To break, type
  9931.           (set! SYMBOL (breakf SYMBOL))
  9932.  
  9933.      or
  9934.           (set! SYMBOL (breakf SYMBOL 'SYMBOL))
  9935.  
  9936.      or
  9937.           (define SYMBOL (breakf FUNCTION))
  9938.  
  9939.      or
  9940.           (define SYMBOL (breakf FUNCTION 'SYMBOL))
  9941.  
  9942.  - Function: unbreakf PROC                                                    |
  9943.      To unbreak, type
  9944.           (set! SYMBOL (unbreakf SYMBOL))
  9945.  
  9946. 
  9947. File: slib.info,  Node: Trace,  Next: System Interface,  Prev: Breakpoints,  Up: Session Support
  9948.  
  9949. Tracing
  9950. -------
  9951.  
  9952.   `(require 'trace)'
  9953.  
  9954. This feature provides three ways to monitor procedure invocations:            |
  9955.                                                                               |
  9956. stack                                                                         |
  9957.      Pushes the procedure-name when the procedure is called; pops when        |
  9958.      it returns.                                                              |
  9959.                                                                               |
  9960. track                                                                         |
  9961.      Pushes the procedure-name and arguments when the procedure is            |
  9962.      called; pops when it returns.                                            |
  9963.                                                                               |
  9964. trace                                                                         |
  9965.      Pushes the procedure-name and prints `CALL PROCEDURE-NAME ARG1           |
  9966.      ...' when the procdure is called; pops and prints `RETN                  |
  9967.      PROCEDURE-NAME VALUE' when the procedure returns.                        |
  9968.                                                                               |
  9969.  - Variable: debug:max-count                                                  |
  9970.      If a traced procedure calls itself or untraced procedures which          |
  9971.      call it, stack, track, and trace will limit the number of stack          |
  9972.      pushes to DEBUG:MAX-COUNT.                                               |
  9973.                                                                               |
  9974.  - Function: print-call-stack                                                 |
  9975.  - Function: print-call-stack PORT                                            |
  9976.      Prints the call-stack to PORT or the current-error-port.                 |
  9977.                                                                               |
  9978.  - Macro: trace PROC1 ...
  9979.      Traces the top-level named procedures given as arguments.
  9980.  
  9981.  - Macro: trace
  9982.      With no arguments, makes sure that all the currently traced
  9983.      identifiers are traced (even if those identifiers have been
  9984.      redefined) and returns a list of the traced identifiers.
  9985.  
  9986.  - Macro: track PROC1 ...                                                     |
  9987.      Traces the top-level named procedures given as arguments.                |
  9988.                                                                               |
  9989.  - Macro: track                                                               |
  9990.      With no arguments, makes sure that all the currently tracked             |
  9991.      identifiers are tracked (even if those identifiers have been             |
  9992.      redefined) and returns a list of the tracked identifiers.                |
  9993.                                                                               |
  9994.  - Macro: stack PROC1 ...                                                     |
  9995.      Traces the top-level named procedures given as arguments.                |
  9996.                                                                               |
  9997.  - Macro: stack                                                               |
  9998.      With no arguments, makes sure that all the currently stacked             |
  9999.      identifiers are stacked (even if those identifiers have been             |
  10000.      redefined) and returns a list of the stacked identifiers.                |
  10001.                                                                               |
  10002.  - Macro: untrace PROC1 ...
  10003.      Turns tracing, tracking, and  off for its arguments.                     |
  10004.  
  10005.  - Macro: untrace
  10006.      With no arguments, untraces all currently traced identifiers and
  10007.      returns a list of these formerly traced identifiers.
  10008.  
  10009.  - Macro: untrack PROC1 ...                                                   |
  10010.      Turns tracing, tracking, and  off for its arguments.                     |
  10011.                                                                               |
  10012.  - Macro: untrack                                                             |
  10013.      With no arguments, untracks all currently tracked identifiers and        |
  10014.      returns a list of these formerly tracked identifiers.                    |
  10015.                                                                               |
  10016.  - Macro: unstack PROC1 ...                                                   |
  10017.      Turns tracing, stacking, and  off for its arguments.                     |
  10018.                                                                               |
  10019.  - Macro: unstack                                                             |
  10020.      With no arguments, unstacks all currently stacked identifiers and        |
  10021.      returns a list of these formerly stacked identifiers.                    |
  10022.                                                                               |
  10023.   These are *procedures* for tracing.  If defmacros are not natively          |
  10024. supported by your implementation, these might be more convenient to use.      |
  10025.  
  10026.  - Function: tracef PROC
  10027.  - Function: tracef PROC NAME                                                 |
  10028.      To trace, type
  10029.           (set! SYMBOL (tracef SYMBOL))
  10030.  
  10031.      or
  10032.           (set! SYMBOL (tracef SYMBOL 'SYMBOL))
  10033.  
  10034.      or
  10035.           (define SYMBOL (tracef FUNCTION))
  10036.  
  10037.      or
  10038.           (define SYMBOL (tracef FUNCTION 'SYMBOL))
  10039.  
  10040.  - Function: untracef PROC
  10041.      Removes tracing, tracking, or stacking for PROC.  To untrace, type       |
  10042.           (set! SYMBOL (untracef SYMBOL))
  10043.  
  10044. 
  10045. File: slib.info,  Node: System Interface,  Prev: Trace,  Up: Session Support
  10046.  
  10047. System Interface
  10048. ----------------
  10049.  
  10050. If `(provided? 'getenv)':
  10051.  
  10052.  - Function: getenv NAME
  10053.      Looks up NAME, a string, in the program environment.  If NAME is
  10054.      found a string of its value is returned.  Otherwise, `#f' is
  10055.      returned.
  10056.  
  10057. If `(provided? 'system)':
  10058.  
  10059.  - Function: system COMMAND-STRING
  10060.      Executes the COMMAND-STRING on the computer and returns the
  10061.      integer status code.
  10062.  
  10063. If `system' is provided by the Scheme implementation, the "net-clients"
  10064. package provides interfaces to common network client programs like FTP,
  10065. mail, and Netscape.
  10066.  
  10067.   `(require 'net-clients)'
  10068.  
  10069.  - Function: call-with-tmpnam PROC
  10070.  - Function: call-with-tmpnam PROC K
  10071.      Calls PROC with K arguments, strings returned by successive calls
  10072.      to `tmpnam'.  If PROC returns, then any files named by the
  10073.      arguments to PROC are deleted automatically and the value(s)
  10074.      yielded by the PROC is(are) returned.  K may be ommited, in which
  10075.      case it defaults to `1'.
  10076.  
  10077.  - Function: user-email-address
  10078.      `user-email-address' returns a string of the form
  10079.      `username@hostname'.  If this e-mail address cannot be obtained,
  10080.      #f is returned.
  10081.  
  10082.  - Function: current-directory
  10083.      `current-directory' returns a string containing the absolute file
  10084.      name representing the current working directory.  If this string
  10085.      cannot be obtained, #f is returned.
  10086.  
  10087.      If `current-directory' cannot be supported by the platform, the
  10088.      value of `current-directory' is #f.
  10089.  
  10090.  - Function: make-directory NAME
  10091.      Creates a sub-directory NAME of the current-directory.  If
  10092.      successful, `make-directory' returns #t; otherwise #f.
  10093.  
  10094.  - Function: null-directory? FILE-NAME
  10095.      Returns #t if changing directory to FILE-NAME makes the current
  10096.      working directory the same as it is before changing directory;
  10097.      otherwise returns #f.
  10098.  
  10099.  - Function: absolute-path? FILE-NAME
  10100.      Returns #t if FILE-NAME is a fully specified pathname (does not
  10101.      depend on the current working directory); otherwise returns #f.
  10102.  
  10103.  - Function: glob-pattern? STR
  10104.      Returns #t if the string STR contains characters used for
  10105.      specifying glob patterns, namely `*', `?', or `['.
  10106.  
  10107.  - Function: parse-ftp-address URL
  10108.      Returns a list of the decoded FTP URL; or #f if indecipherable.
  10109.      FTP "Uniform Resource Locator", "ange-ftp", and "getit" formats
  10110.      are handled.  The returned list has four elements which are
  10111.      strings or #f:
  10112.  
  10113.        0. username
  10114.  
  10115.        1. password
  10116.  
  10117.        2. remote-site
  10118.  
  10119.        3. remote-directory
  10120.  
  10121.  - Function: ftp-upload PATHS USER PASSWORD REMOTE-SITE REMOTE-DIR
  10122.      PASSWORD must be a non-empty string or #f.  PATHS must be a
  10123.      non-empty list of pathnames or Glob patterns (*note Filenames::.)
  10124.      matching files to transfer.
  10125.  
  10126.      `ftp-upload' puts the files specified by PATHS into the REMOTE-DIR
  10127.      directory of FTP REMOTE-SITE using name USER with (optional)
  10128.      PASSWORD.
  10129.  
  10130.      If PASSWORD is #f and USER is not `ftp' or `anonymous', then USER
  10131.      is ignored; FTP takes the username and password from the `.netrc'
  10132.      or equivalent file.
  10133.  
  10134.  - Function: path->url PATH
  10135.      Returns a URL-string for PATH on the local host.
  10136.  
  10137.  - Function: browse-url-netscape URL
  10138.      If a `netscape' browser is running, `browse-url-netscape' causes
  10139.      the browser to display the page specified by string URL and
  10140.      returns #t.
  10141.  
  10142.      If the browser is not running, `browse-url-netscape' runs
  10143.      `netscape' with the argument URL.  If the browser starts as a
  10144.      background job, `browse-url-netscape' returns #t immediately; if
  10145.      the browser starts as a foreground job, then `browse-url-netscape'
  10146.      returns #t when the browser exits; otherwise it returns #f.
  10147.  
  10148. 
  10149. File: slib.info,  Node: Extra-SLIB Packages,  Prev: Session Support,  Up: Other Packages
  10150.  
  10151. Extra-SLIB Packages
  10152. ===================
  10153.  
  10154.   Several Scheme packages have been written using SLIB.  There are
  10155. several reasons why a package might not be included in the SLIB
  10156. distribution:
  10157.    * Because it requires special hardware or software which is not
  10158.      universal.
  10159.  
  10160.    * Because it is large and of limited interest to most Scheme users.
  10161.  
  10162.    * Because it has copying terms different enough from the other SLIB
  10163.      packages that its inclusion would cause confusion.
  10164.  
  10165.    * Because it is an application program, rather than a library module.
  10166.  
  10167.    * Because I have been too busy to integrate it.
  10168.  
  10169.   Once an optional package is installed (and an entry added to
  10170. `*catalog*', the `require' mechanism allows it to be called up and used
  10171. as easily as any other SLIB package.  Some optional packages (for which
  10172. `*catalog*' already has entries) available from SLIB sites are:
  10173.  
  10174. SLIB-PSD                                                                      |
  10175.      is a portable debugger for Scheme (requires emacs editor).               |
  10176.                                                                               |
  10177.      http://swissnet.ai.mit.edu/ftpdir/scm/slib-psd1-3.tar.gz
  10178.                                                                               |
  10179.      swissnet.ai.mit.edu:/pub/scm/slib-psd1-3.tar.gz                          |
  10180.                                                                               |
  10181.      ftp.maths.tcd.ie:pub/bosullvn/jacal/slib-psd1-3.tar.gz
  10182.  
  10183.      ftp.cs.indiana.edu:/pub/scheme-repository/utl/slib-psd1-3.tar.gz
  10184.  
  10185.      With PSD, you can run a Scheme program in an Emacs buffer, set
  10186.      breakpoints, single step evaluation and access and modify the
  10187.      program's variables. It works by instrumenting the original source
  10188.      code, so it should run with any R4RS compliant Scheme. It has been
  10189.      tested with SCM, Elk 1.5, and the sci interpreter in the Scheme->C
  10190.      system, but should work with other Schemes with a minimal amount
  10191.      of porting, if at all. Includes documentation and user's manual.
  10192.      Written by Pertti Kellom\"aki, pk@cs.tut.fi.  The Lisp Pointers
  10193.      article describing PSD (Lisp Pointers VI(1):15-23, January-March
  10194.      1993) is available as
  10195.      http://www.cs.tut.fi/staff/pk/scheme/psd/article/article.html            |
  10196.  
  10197. SCHELOG                                                                       |
  10198.      is an embedding of Prolog in Scheme.                                     |
  10199.      http://www.cs.rice.edu/CS/PLT/packages/schelog/                          |
  10200.                                                                               |
  10201. JFILTER                                                                       |
  10202.      is a Scheme program which converts text among the JIS, EUC, and          |
  10203.      Shift-JIS Japanese character sets.                                       |
  10204.      http://swissnet.ai.mit.edu/~jaffer/jfilter/index.html                    |
  10205.  
  10206. 
  10207. File: slib.info,  Node: About SLIB,  Next: Index,  Prev: Other Packages,  Up: Top
  10208.  
  10209. About SLIB
  10210. **********
  10211.  
  10212. More people than I can name have contributed to SLIB.  Thanks to all of
  10213. you!
  10214.  
  10215.      SLIB 2c8, released June 2000.                                            |
  10216.      Aubrey Jaffer <jaffer @ ai.mit.edu>
  10217.      Hyperactive Software - The Maniac Inside!
  10218.      `http://swissnet.ai.mit.edu/~jaffer/SLIB.html'
  10219.  
  10220. * Menu:
  10221.  
  10222. * Installation::                How to install SLIB on your system.
  10223. * Porting::                     SLIB to new platforms.
  10224. * Coding Guidelines::           How to write modules for SLIB.                |
  10225. * Copyrights::                  Intellectual propery issues.
  10226.  
  10227. 
  10228. File: slib.info,  Node: Installation,  Next: Porting,  Prev: About SLIB,  Up: About SLIB
  10229.  
  10230. Installation
  10231. ============
  10232.  
  10233.   Check the manifest in `README' to find a configuration file for your
  10234. Scheme implementation.  Initialization files for most IEEE P1178
  10235. compliant Scheme Implementations are included with this distribution.
  10236.  
  10237.   If the Scheme implementation supports `getenv', then the value of the
  10238. shell environment variable SCHEME_LIBRARY_PATH will be used for
  10239. `(library-vicinity)' if it is defined.  Currently, Chez, Elk,
  10240. MITScheme, scheme->c, VSCM, and SCM support `getenv'.  Scheme48
  10241. supports `getenv' but does not use it for determining
  10242. `library-vicinity'.  (That is done from the Makefile.)
  10243.  
  10244.   You should check the definitions of `software-type',
  10245. `scheme-implementation-version', `implementation-vicinity', and
  10246. `library-vicinity' in the initialization file.  There are comments in
  10247. the file for how to configure it.
  10248.  
  10249.   Once this is done you can modify the startup file for your Scheme
  10250. implementation to `load' this initialization file.  SLIB is then
  10251. installed.
  10252.  
  10253.   Multiple implementations of Scheme can all use the same SLIB
  10254. directory.  Simply configure each implementation's initialization file
  10255. as outlined above.
  10256.  
  10257.   The SCM implementation does not require any initialization file as
  10258. SLIB support is already built in to SCM.  See the documentation with
  10259. SCM for installation instructions.
  10260.  
  10261.   SLIB includes methods to create heap images for the VSCM and Scheme48
  10262. implementations.  The instructions for creating a VSCM image are in
  10263. comments in `vscm.init'.  To make a Scheme48 image for an installation
  10264. under `<prefix>', `cd' to the SLIB directory and type `make
  10265. prefix=<prefix> slib48'.  To install the image, type `make
  10266. prefix=<prefix> install48'.  This will also create a shell script with
  10267. the name `slib48' which will invoke the saved image.
  10268.  
  10269. 
  10270. File: slib.info,  Node: Porting,  Next: Coding Guidelines,  Prev: Installation,  Up: About SLIB
  10271.                                                                               |
  10272. Porting
  10273. =======
  10274.  
  10275.   If there is no initialization file for your Scheme implementation, you
  10276. will have to create one.  Your Scheme implementation must be largely
  10277. compliant with `IEEE Std 1178-1990', `Revised^4 Report on the
  10278. Algorithmic Language Scheme', or `Revised^5 Report on the Algorithmic
  10279. Language Scheme' in order to support SLIB.  (1)
  10280.  
  10281.   `Template.scm' is an example configuration file.  The comments inside
  10282. will direct you on how to customize it to reflect your system.  Give
  10283. your new initialization file the implementation's name with `.init'
  10284. appended.  For instance, if you were porting `foo-scheme' then the
  10285. initialization file might be called `foo.init'.
  10286.  
  10287.   Your customized version should then be loaded as part of your scheme
  10288. implementation's initialization.  It will load `require.scm' from the
  10289. library; this will allow the use of `provide', `provided?', and
  10290. `require' along with the "vicinity" functions (these functions are
  10291. documented in the section *Note Require::).  The rest of the library
  10292. will then be accessible in a system independent fashion.
  10293.  
  10294.   Please mail new working configuration files to `jaffer @ ai.mit.edu'
  10295. so that they can be included in the SLIB distribution.
  10296.  
  10297.   ---------- Footnotes ----------
  10298.  
  10299.   (1) If you are porting a `Revised^3 Report on the Algorithmic
  10300. Language Scheme' implementation, then you will need to finish writing
  10301. `sc4sc3.scm' and `load' it from your initialization file.
  10302.  
  10303. 
  10304. File: slib.info,  Node: Coding Guidelines,  Next: Copyrights,  Prev: Porting,  Up: About SLIB
  10305.                                                                               |
  10306. Coding Guidelines                                                             |
  10307. =================                                                             |
  10308.  
  10309.   All library packages are written in IEEE P1178 Scheme and assume that
  10310. a configuration file and `require.scm' package have already been
  10311. loaded.  Other versions of Scheme can be supported in library packages
  10312. as well by using, for example, `(provided? 'rev3-report)' or `(require
  10313. 'rev3-report)' (*note Require::.).
  10314.  
  10315.   The module name and `:' should prefix each symbol defined in the
  10316. package.  Definitions for external use should then be exported by having
  10317. `(define foo module-name:foo)'.
  10318.  
  10319.   Code submitted for inclusion in SLIB should not duplicate routines
  10320. already in SLIB files.  Use `require' to force those library routines
  10321. to be used by your package.  Care should be taken that there are no
  10322. circularities in the `require's and `load's between the library
  10323. packages.
  10324.  
  10325.   Documentation should be provided in Emacs Texinfo format if possible,
  10326. But documentation must be provided.
  10327.  
  10328.   Your package will be released sooner with SLIB if you send me a file
  10329. which tests your code.  Please run this test *before* you send me the
  10330. code!
  10331.  
  10332. Modifications
  10333. -------------
  10334.  
  10335.   Please document your changes.  A line or two for `ChangeLog' is
  10336. sufficient for simple fixes or extensions.  Look at the format of
  10337. `ChangeLog' to see what information is desired.  Please send me `diff'
  10338. files from the latest SLIB distribution (remember to send `diff's of
  10339. `slib.texi' and `ChangeLog').  This makes for less email traffic and
  10340. makes it easier for me to integrate when more than one person is
  10341. changing a file (this happens a lot with `slib.texi' and `*.init'
  10342. files).
  10343.  
  10344.   If someone else wrote a package you want to significantly modify,
  10345. please try to contact the author, who may be working on a new version.
  10346. This will insure against wasting effort on obsolete versions.
  10347.  
  10348.   Please *do not* reformat the source code with your favorite
  10349. beautifier, make 10 fixes, and send me the resulting source code.  I do
  10350. not have the time to fish through 10000 diffs to find your 10 real
  10351. fixes.
  10352.  
  10353. 
  10354. File: slib.info,  Node: Copyrights,  Prev: Coding Guidelines,  Up: About SLIB
  10355.                                                                               |
  10356. Copyrights
  10357. ==========
  10358.  
  10359.   This section has instructions for SLIB authors regarding copyrights.
  10360.  
  10361.   Each package in SLIB must either be in the public domain, or come
  10362. with a statement of terms permitting users to copy, redistribute and
  10363. modify it.  The comments at the beginning of `require.scm' and
  10364. `macwork.scm' illustrate copyright and appropriate terms.
  10365.  
  10366.   If your code or changes amount to less than about 10 lines, you do not
  10367. need to add your copyright or send a disclaimer.
  10368.  
  10369. Putting code into the Public Domain
  10370. -----------------------------------
  10371.  
  10372.   In order to put code in the public domain you should sign a copyright
  10373. disclaimer and send it to the SLIB maintainer.  Contact jaffer @
  10374. ai.mit.edu for the address to mail the disclaimer to.
  10375.  
  10376.      I, NAME, hereby affirm that I have placed the software package
  10377.      NAME in the public domain.
  10378.  
  10379.      I affirm that I am the sole author and sole copyright holder for
  10380.      the software package, that I have the right to place this software
  10381.      package in the public domain, and that I will do nothing to
  10382.      undermine this status in the future.
  10383.  
  10384.                                                      SIGNATURE AND DATE
  10385.  
  10386.   This wording assumes that you are the sole author.  If you are not the
  10387. sole author, the wording needs to be different.  If you don't want to be
  10388. bothered with sending a letter every time you release or modify a
  10389. module, make your letter say that it also applies to your future
  10390. revisions of that module.
  10391.  
  10392.   Make sure no employer has any claim to the copyright on the work you
  10393. are submitting.  If there is any doubt, create a copyright disclaimer
  10394. and have your employer sign it.  Mail the signed disclaimer to the SLIB
  10395. maintainer.  Contact jaffer @ ai.mit.edu for the address to mail the
  10396. disclaimer to.  An example disclaimer follows.
  10397.  
  10398. Explicit copying terms
  10399. ----------------------
  10400.  
  10401. If you submit more than about 10 lines of code which you are not placing
  10402. into the Public Domain (by sending me a disclaimer) you need to:
  10403.  
  10404.    * Arrange that your name appears in a copyright line for the
  10405.      appropriate year.   Multiple copyright lines are acceptable.
  10406.  
  10407.    * With your copyright line, specify any terms you require to be
  10408.      different from those already in the file.
  10409.  
  10410.    * Make sure no employer has any claim to the copyright on the work
  10411.      you are submitting.  If there is any doubt, create a copyright
  10412.      disclaimer and have your employer sign it.  Mail the signed
  10413.      disclaim to the SLIB maintainer.  Contact jaffer @ ai.mit.edu for
  10414.      the address to mail the disclaimer to.
  10415.  
  10416. Example: Company Copyright Disclaimer
  10417. -------------------------------------
  10418.  
  10419.   This disclaimer should be signed by a vice president or general
  10420. manager of the company.  If you can't get at them, anyone else
  10421. authorized to license out software produced there will do.  Here is a
  10422. sample wording:
  10423.  
  10424.      EMPLOYER Corporation hereby disclaims all copyright interest in
  10425.      the program PROGRAM written by NAME.
  10426.  
  10427.      EMPLOYER Corporation affirms that it has no other intellectual
  10428.      property interest that would undermine this release, and will do
  10429.      nothing to undermine it in the future.
  10430.  
  10431.      SIGNATURE AND DATE,
  10432.      NAME, TITLE, EMPLOYER Corporation
  10433.  
  10434. 
  10435. File: slib.info,  Node: Index,  Prev: About SLIB,  Up: Top
  10436.  
  10437. Procedure and Macro Index
  10438. *************************
  10439.  
  10440.   This is an alphabetical list of all the procedures and macros in SLIB.
  10441.  
  10442. * Menu:
  10443.  
  10444. * -:                                     Multi-argument / and -.
  10445. * -1+:                                   Rev2 Procedures.
  10446. * /:                                     Multi-argument / and -.
  10447. * 1+:                                    Rev2 Procedures.
  10448. * <=?:                                   Rev2 Procedures.
  10449. * <?:                                    Rev2 Procedures.
  10450. * =?:                                    Rev2 Procedures.
  10451. * >=?:                                   Rev2 Procedures.
  10452. * >?:                                    Rev2 Procedures.
  10453. * absolute-path?:                        System Interface.
  10454. * add-domain:                            Database Utilities.
  10455. * add-process!:                          Multi-Processing.
  10456. * add-setter:                            Setters.
  10457. * adjoin:                                Lists as sets.
  10458. * adjoin-parameters!:                    Parameter lists.
  10459. * alarm:                                 Multi-Processing.
  10460. * alarm-interrupt:                       Multi-Processing.
  10461. * alist->wt-tree:                        Construction of Weight-Balanced Trees.
  10462. * alist-associator:                      Association Lists.
  10463. * alist-for-each:                        Association Lists.
  10464. * alist-inquirer:                        Association Lists.
  10465. * alist-map:                             Association Lists.
  10466. * alist-remover:                         Association Lists.
  10467. * and?:                                  Non-List functions.
  10468. * any?:                                  Collections.
  10469. * append!:                               Rev2 Procedures.
  10470. * apply:                                 Multi-argument Apply.
  10471. * array-1d-ref:                          Arrays.
  10472. * array-1d-set!:                         Arrays.
  10473. * array-2d-ref:                          Arrays.
  10474. * array-2d-set!:                         Arrays.
  10475. * array-3d-ref:                          Arrays.
  10476. * array-3d-set!:                         Arrays.
  10477. * array-copy!:                           Array Mapping.
  10478. * array-dimensions:                      Arrays.
  10479. * array-for-each:                        Array Mapping.
  10480. * array-in-bounds?:                      Arrays.
  10481. * array-index-map!:                      Array Mapping.
  10482. * array-indexes:                         Array Mapping.
  10483. * array-map!:                            Array Mapping.
  10484. * array-rank:                            Arrays.
  10485. * array-ref:                             Arrays.
  10486. * array-set!:                            Arrays.
  10487. * array-shape:                           Arrays.
  10488. * array?:                                Arrays.
  10489. * asctime:                               Posix Time.
  10490. * ash:                                   Bit-Twiddling.
  10491. * atom?:                                 Non-List functions.
  10492. * batch:call-with-output-script:         Batch.
  10493. * batch:command:                         Batch.
  10494. * batch:comment:                         Batch.
  10495. * batch:delete-file:                     Batch.
  10496. * batch:initialize!:                     Batch.
  10497. * batch:lines->file:                     Batch.
  10498. * batch:rename-file:                     Batch.
  10499. * batch:run-script:                      Batch.
  10500. * batch:try-chopped-command:             Batch.
  10501. * batch:try-command:                     Batch.
  10502. * bit-extract:                           Bit-Twiddling.
  10503. * bit-field:                             Bit-Twiddling.
  10504. * bitwise-if:                            Bit-Twiddling.
  10505. * break:                                 Breakpoints.
  10506. * break-all:                             Debug.
  10507. * breakf:                                Breakpoints.
  10508. * breakpoint:                            Breakpoints.
  10509. * browse:                                Database Browser.
  10510. * browse-url-netscape:                   System Interface.
  10511. * butlast:                               Lists as sequences.
  10512. * butnthcdr:                             Lists as sequences.
  10513. * byte-ref:                              Byte.
  10514. * byte-set!:                             Byte.
  10515. * bytes:                                 Byte.
  10516. * bytes->list:                           Byte.
  10517. * bytes-length:                          Byte.
  10518. * call-with-dynamic-binding:             Dynamic Data Type.
  10519. * call-with-input-string:                String Ports.
  10520. * call-with-output-string:               String Ports.
  10521. * call-with-tmpnam:                      System Interface.
  10522. * call-with-values:                      Values.
  10523. * capture-syntactic-environment:         Syntactic Closures.
  10524. * cart-prod-tables:                      Relational Database Operations.
  10525. * catalog->html:                         HTML HTTP and CGI.
  10526. * catalog->page:                         HTML HTTP and CGI.
  10527. * cgi:read-query-string:                 HTML HTTP and CGI.
  10528. * cgi:serve-command:                     HTML HTTP and CGI.
  10529. * chap:next-string:                      Chapter Ordering.
  10530. * chap:string<=?:                        Chapter Ordering.
  10531. * chap:string<?:                         Chapter Ordering.
  10532. * chap:string>=?:                        Chapter Ordering.
  10533. * chap:string>?:                         Chapter Ordering.
  10534. * check-parameters:                      Parameter lists.
  10535. * close-base:                            Base Table.
  10536. * close-database:                        Relational Database Operations.
  10537. * close-table:                           Table Operations.
  10538. * coerce:                                Non-List functions.
  10539. * collection?:                           Collections.
  10540. * combined-rulesets:                     Commutative Rings.
  10541. * command->html:                         HTML HTTP and CGI.
  10542. * continue:                              Breakpoints.
  10543. * copy-bit:                              Bit-Twiddling.
  10544. * copy-bit-field:                        Bit-Twiddling.
  10545. * copy-list:                             List construction.
  10546. * copy-random-state:                     Random Numbers.
  10547. * copy-tree:                             Tree Operations.
  10548. * create-database <1>:                   Database Utilities.
  10549. * create-database:                       Creating and Opening Relational Databases.
  10550. * create-report:                         Database Reports.
  10551. * create-table:                          Relational Database Operations.
  10552. * create-view:                           Relational Database Operations.
  10553. * cring:define-rule:                     Commutative Rings.
  10554. * ctime:                                 Posix Time.
  10555. * current-directory:                     System Interface.
  10556. * current-error-port:                    Input/Output.
  10557. * current-input-port <1>:                Byte.
  10558. * current-input-port:                    Ruleset Definition and Use.
  10559. * current-output-port:                   Byte.
  10560. * current-time:                          Time and Date.
  10561. * db->directory:                         HTML HTTP and CGI.                   |
  10562. * db->files:                             HTML HTTP and CGI.                   |
  10563. * db->netscape:                          HTML HTTP and CGI.                   |
  10564. * decode-universal-time:                 Common-Lisp Time.
  10565. * define-access-operation:               Setters.
  10566. * define-operation:                      Yasos interface.
  10567. * define-predicate:                      Yasos interface.
  10568. * define-record:                         Structures.
  10569. * define-syntax:                         Macro by Example.
  10570. * define-tables:                         Database Utilities.
  10571. * defmacro:                              Defmacro.
  10572. * defmacro:eval:                         Defmacro.
  10573. * defmacro:expand*:                      Defmacro.
  10574. * defmacro:load:                         Defmacro.
  10575. * defmacro?:                             Defmacro.
  10576. * delete <1>:                            Destructive list operations.
  10577. * delete:                                Base Table.
  10578. * delete*:                               Base Table.
  10579. * delete-domain:                         Database Utilities.
  10580. * delete-file:                           Input/Output.
  10581. * delete-if:                             Destructive list operations.
  10582. * delete-if-not:                         Destructive list operations.
  10583. * delete-table:                          Relational Database Operations.
  10584. * dequeue!:                              Queues.
  10585. * difftime:                              Time and Date.
  10586. * display-file:                          Line I/O.
  10587. * do-elts:                               Collections.
  10588. * do-keys:                               Collections.
  10589. * domain-checker:                        Database Utilities.
  10590. * dynamic-ref:                           Dynamic Data Type.
  10591. * dynamic-set!:                          Dynamic Data Type.
  10592. * dynamic-wind:                          Dynamic-Wind.
  10593. * dynamic?:                              Dynamic Data Type.
  10594. * empty?:                                Collections.
  10595. * encode-universal-time:                 Common-Lisp Time.
  10596. * enquque!:                              Queues.
  10597. * equal?:                                Byte.
  10598. * eval:                                  Eval.
  10599. * every:                                 Lists as sets.
  10600. * every?:                                Collections.
  10601. * extended-euclid:                       Modular Arithmetic.
  10602. * factor:                                Prime Numbers.
  10603. * fft:                                   Fast Fourier Transform.
  10604. * fft-1:                                 Fast Fourier Transform.
  10605. * file-exists?:                          Input/Output.
  10606. * filename:match-ci??:                   Filenames.
  10607. * filename:match??:                      Filenames.
  10608. * filename:substitute-ci??:              Filenames.
  10609. * filename:substitute??:                 Filenames.
  10610. * fill-empty-parameters:                 Parameter lists.
  10611. * find-if:                               Lists as sets.
  10612. * find-ratio:                            Rationalize.                         |
  10613. * find-ratio-between:                    Rationalize.                         |
  10614. * find-string-from-port?:                String Search.
  10615. * fluid-let:                             Fluid-Let.
  10616. * for-each-elt:                          Collections.
  10617. * for-each-key <1>:                      Collections.
  10618. * for-each-key:                          Base Table.
  10619. * for-each-row:                          Table Operations.
  10620. * force-output:                          Input/Output.
  10621. * format:                                Format Interface.
  10622. * fprintf:                               Standard Formatted Output.
  10623. * fscanf:                                Standard Formatted Input.
  10624. * ftp-upload:                            System Interface.
  10625. * generic-write:                         Generic-Write.
  10626. * gentemp:                               Defmacro.
  10627. * get:                                   Table Operations.
  10628. * get*:                                  Table Operations.
  10629. * get-decoded-time:                      Common-Lisp Time.
  10630. * get-method:                            Object.
  10631. * get-universal-time:                    Common-Lisp Time.
  10632. * getenv:                                System Interface.
  10633. * getopt:                                Getopt.
  10634. * getopt--:                              Getopt.
  10635. * getopt->arglist:                       Getopt Parameter lists.
  10636. * getopt->parameter-list:                Getopt Parameter lists.
  10637. * glob-pattern?:                         System Interface.
  10638. * gmktime:                               Posix Time.
  10639. * gmtime:                                Posix Time.
  10640. * golden-section-search:                 Minimizing.                          |
  10641. * gtime:                                 Posix Time.
  10642. * has-duplicates?:                       Lists as sets.
  10643. * hash:                                  Hashing.
  10644. * hash-associator:                       Hash Tables.
  10645. * hash-for-each:                         Hash Tables.
  10646. * hash-inquirer:                         Hash Tables.
  10647. * hash-map:                              Hash Tables.
  10648. * hash-remover:                          Hash Tables.
  10649. * hashq:                                 Hashing.
  10650. * hashv:                                 Hashing.
  10651. * heap-extract-max!:                     Priority Queues.
  10652. * heap-insert!:                          Priority Queues.
  10653. * heap-length:                           Priority Queues.
  10654. * home-vicinity:                         Vicinity.
  10655. * html:comment:                          HTML HTTP and CGI.
  10656. * html:end-form:                         HTML HTTP and CGI.
  10657. * html:end-page:                         HTML HTTP and CGI.
  10658. * html:end-table:                        HTML HTTP and CGI.
  10659. * html:heading:                          HTML HTTP and CGI.
  10660. * html:href-heading:                     HTML HTTP and CGI.
  10661. * html:pre:                              HTML HTTP and CGI.
  10662. * html:start-form:                       HTML HTTP and CGI.
  10663. * html:start-page:                       HTML HTTP and CGI.
  10664. * html:start-table:                      HTML HTTP and CGI.
  10665. * http:read-request-line:                HTML HTTP and CGI.
  10666. * http:serve-query:                      HTML HTTP and CGI.
  10667. * http:serve-uri:                        HTML HTTP and CGI.                   |
  10668. * identifier=?:                          Syntactic Closures.
  10669. * identifier?:                           Syntactic Closures.
  10670. * identity:                              Legacy.
  10671. * implementation-vicinity:               Vicinity.
  10672. * in-vicinity:                           Vicinity.
  10673. * init-debug:                            Breakpoints.
  10674. * integer-expt:                          Bit-Twiddling.
  10675. * integer-length:                        Bit-Twiddling.
  10676. * integer-sqrt:                          Root Finding.
  10677. * interaction-environment:               Eval.
  10678. * intersection:                          Lists as sets.
  10679. * jacobi-symbol:                         Prime Numbers.
  10680. * kill-process!:                         Multi-Processing.
  10681. * kill-table:                            Base Table.
  10682. * laguerre:find-polynomial-root:         Root Finding.
  10683. * laguerre:find-root:                    Root Finding.
  10684. * last:                                  Lists as sequences.
  10685. * last-pair:                             Legacy.
  10686. * library-vicinity:                      Vicinity.
  10687. * list*:                                 List construction.
  10688. * list->bytes:                           Byte.
  10689. * list->string:                          Rev4 Optional Procedures.
  10690. * list->vector:                          Rev4 Optional Procedures.
  10691. * list-tail:                             Rev4 Optional Procedures.
  10692. * load-option:                           Weight-Balanced Trees.
  10693. * localtime:                             Posix Time.
  10694. * logand:                                Bit-Twiddling.
  10695. * logbit?:                               Bit-Twiddling.
  10696. * logcount:                              Bit-Twiddling.
  10697. * logior:                                Bit-Twiddling.
  10698. * lognot:                                Bit-Twiddling.
  10699. * logtest:                               Bit-Twiddling.
  10700. * logxor:                                Bit-Twiddling.
  10701. * macro:eval <1>:                        Syntax-Case Macros.
  10702. * macro:eval <2>:                        Syntactic Closures.
  10703. * macro:eval <3>:                        Macros That Work.
  10704. * macro:eval:                            R4RS Macros.
  10705. * macro:expand <1>:                      Syntax-Case Macros.
  10706. * macro:expand <2>:                      Syntactic Closures.
  10707. * macro:expand <3>:                      Macros That Work.
  10708. * macro:expand:                          R4RS Macros.
  10709. * macro:load <1>:                        Syntax-Case Macros.
  10710. * macro:load <2>:                        Syntactic Closures.
  10711. * macro:load <3>:                        Macros That Work.
  10712. * macro:load:                            R4RS Macros.
  10713. * macroexpand:                           Defmacro.
  10714. * macroexpand-1:                         Defmacro.
  10715. * macwork:eval:                          Macros That Work.
  10716. * macwork:expand:                        Macros That Work.
  10717. * macwork:load:                          Macros That Work.
  10718. * make-:                                 Structures.
  10719. * make-array:                            Arrays.
  10720. * make-atval:                            HTML HTTP and CGI.
  10721. * make-base:                             Base Table.
  10722. * make-bytes:                            Byte.
  10723. * make-command-server:                   Database Utilities.
  10724. * make-directory:                        System Interface.
  10725. * make-dynamic:                          Dynamic Data Type.
  10726. * make-generic-method:                   Object.
  10727. * make-generic-predicate:                Object.
  10728. * make-getter:                           Base Table.
  10729. * make-hash-table:                       Hash Tables.
  10730. * make-heap:                             Priority Queues.
  10731. * make-key->list:                        Base Table.
  10732. * make-key-extractor:                    Base Table.
  10733. * make-keyifier-1:                       Base Table.
  10734. * make-list:                             List construction.
  10735. * make-list-keyifier:                    Base Table.
  10736. * make-method!:                          Object.
  10737. * make-object:                           Object.
  10738. * make-parameter-list:                   Parameter lists.
  10739. * make-plain:                            HTML HTTP and CGI.
  10740. * make-port-crc:                         Cyclic Checksum.
  10741. * make-predicate!:                       Object.
  10742. * make-promise:                          Promises.
  10743. * make-putter:                           Base Table.
  10744. * make-queue:                            Queues.
  10745. * make-random-state:                     Random Numbers.
  10746. * make-record-type:                      Records.
  10747. * make-relational-system:                Creating and Opening Relational Databases.
  10748. * make-row-converter:                    HTML HTTP and CGI.
  10749. * make-ruleset:                          Commutative Rings.
  10750. * make-shared-array:                     Arrays.
  10751. * make-sierpinski-indexer:               Hashing.
  10752. * make-syntactic-closure:                Syntactic Closures.
  10753. * make-table:                            Base Table.
  10754. * make-vicinity:                         Vicinity.
  10755. * make-wt-tree:                          Construction of Weight-Balanced Trees.
  10756. * make-wt-tree-type:                     Construction of Weight-Balanced Trees.
  10757. * map-elts:                              Collections.
  10758. * map-key:                               Base Table.
  10759. * map-keys:                              Collections.
  10760. * member-if:                             Lists as sets.
  10761. * merge:                                 Sorting.
  10762. * merge!:                                Sorting.
  10763. * mktime:                                Posix Time.
  10764. * modular::                              Modular Arithmetic.
  10765. * modular:*:                             Modular Arithmetic.
  10766. * modular:+:                             Modular Arithmetic.
  10767. * modular:expt:                          Modular Arithmetic.
  10768. * modular:invert:                        Modular Arithmetic.
  10769. * modular:invertable?:                   Modular Arithmetic.
  10770. * modular:negate:                        Modular Arithmetic.
  10771. * modular:normalize:                     Modular Arithmetic.
  10772. * modulus->integer:                      Modular Arithmetic.
  10773. * must-be-first:                         Batch.
  10774. * must-be-last:                          Batch.
  10775. * nconc:                                 Destructive list operations.
  10776. * newton:find-root:                      Root Finding.
  10777. * newtown:find-integer-root:             Root Finding.
  10778. * notany:                                Lists as sets.
  10779. * notevery:                              Lists as sets.
  10780. * nreverse:                              Destructive list operations.
  10781. * nthcdr:                                Lists as sequences.
  10782. * null-directory?:                       System Interface.
  10783. * null-environment:                      Eval.
  10784. * object:                                Yasos interface.
  10785. * object->limited-string:                Object-To-String.
  10786. * object->string:                        Object-To-String.
  10787. * object-with-ancestors:                 Yasos interface.
  10788. * object?:                               Object.
  10789. * offset-time:                           Time and Date.
  10790. * open-base:                             Base Table.
  10791. * open-database <1>:                     Database Utilities.
  10792. * open-database:                         Creating and Opening Relational Databases.
  10793. * open-database!:                        Database Utilities.
  10794. * open-table <1>:                        Relational Database Operations.
  10795. * open-table:                            Base Table.
  10796. * operate-as:                            Yasos interface.
  10797. * or?:                                   Non-List functions.
  10798. * ordered-for-each-key:                  Base Table.
  10799. * os->batch-dialect:                     Batch.
  10800. * output-port-height:                    Input/Output.
  10801. * output-port-width:                     Input/Output.
  10802. * parameter-list->arglist:               Parameter lists.
  10803. * parameter-list-expand:                 Parameter lists.
  10804. * parameter-list-ref:                    Parameter lists.
  10805. * parse-ftp-address:                     System Interface.
  10806. * path->url:                             System Interface.
  10807. * plot!:                                 Plotting.
  10808. * position:                              Lists as sequences.
  10809. * pprint-file:                           Pretty-Print.
  10810. * pprint-filter-file:                    Pretty-Print.
  10811. * prec:commentfix:                       Grammar Rule Definition.
  10812. * prec:define-grammar:                   Ruleset Definition and Use.
  10813. * prec:delim:                            Grammar Rule Definition.
  10814. * prec:infix:                            Grammar Rule Definition.
  10815. * prec:inmatchfix:                       Grammar Rule Definition.
  10816. * prec:make-led:                         Nud and Led Definition.
  10817. * prec:make-nud:                         Nud and Led Definition.
  10818. * prec:matchfix:                         Grammar Rule Definition.
  10819. * prec:nary:                             Grammar Rule Definition.
  10820. * prec:nofix:                            Grammar Rule Definition.
  10821. * prec:parse:                            Ruleset Definition and Use.
  10822. * prec:postfix:                          Grammar Rule Definition.
  10823. * prec:prefix:                           Grammar Rule Definition.
  10824. * prec:prestfix:                         Grammar Rule Definition.
  10825. * predicate->asso:                       Association Lists.
  10826. * predicate->hash:                       Hash Tables.
  10827. * predicate->hash-asso:                  Hash Tables.
  10828. * present?:                              Base Table.
  10829. * pretty-print:                          Pretty-Print.
  10830. * prime?:                                Prime Numbers.
  10831. * primes<:                               Prime Numbers.
  10832. * primes>:                               Prime Numbers.
  10833. * print:                                 Yasos interface.
  10834. * print-call-stack:                      Trace.                               |
  10835. * printf:                                Standard Formatted Output.
  10836. * process:schedule!:                     Multi-Processing.
  10837. * program-vicinity:                      Vicinity.
  10838. * project-table:                         Relational Database Operations.
  10839. * provide <1>:                           Require.
  10840. * provide:                               Feature.
  10841. * provided? <1>:                         Require.
  10842. * provided?:                             Feature.
  10843. * qp:                                    Quick Print.
  10844. * qpn:                                   Quick Print.
  10845. * qpr:                                   Quick Print.
  10846. * queue-empty?:                          Queues.
  10847. * queue-front:                           Queues.
  10848. * queue-pop!:                            Queues.
  10849. * queue-push!:                           Queues.
  10850. * queue-rear:                            Queues.
  10851. * queue?:                                Queues.
  10852. * random:                                Random Numbers.
  10853. * random:exp:                            Random Numbers.
  10854. * random:hollow-sphere!:                 Random Numbers.
  10855. * random:normal:                         Random Numbers.
  10856. * random:normal-vector!:                 Random Numbers.
  10857. * random:solid-sphere!:                  Random Numbers.
  10858. * random:uniform:                        Random Numbers.
  10859. * rationalize:                           Rationalize.
  10860. * read-byte:                             Byte.
  10861. * read-command:                          Command Line.
  10862. * read-line:                             Line I/O.
  10863. * read-line!:                            Line I/O.
  10864. * read-options-file:                     Command Line.
  10865. * record-accessor:                       Records.
  10866. * record-constructor:                    Records.
  10867. * record-modifier:                       Records.
  10868. * record-predicate:                      Records.
  10869. * reduce <1>:                            Lists as sequences.
  10870. * reduce:                                Collections.
  10871. * reduce-init:                           Lists as sequences.
  10872. * remove:                                Lists as sets.
  10873. * remove-duplicates:                     Lists as sets.
  10874. * remove-if:                             Lists as sets.
  10875. * remove-if-not:                         Lists as sets.
  10876. * remove-setter-for:                     Setters.
  10877. * repl:quit:                             Repl.
  10878. * repl:top-level:                        Repl.
  10879. * replace-suffix:                        Filenames.
  10880. * require <1>:                           Require.
  10881. * require <2>:                           Catalog Compilation.
  10882. * require:                               Requesting Features.
  10883. * require:feature->path <1>:             Require.
  10884. * require:feature->path:                 Requesting Features.
  10885. * restrict-table:                        Relational Database Operations.
  10886. * row:delete:                            Table Operations.
  10887. * row:delete*:                           Table Operations.
  10888. * row:insert:                            Table Operations.
  10889. * row:insert*:                           Table Operations.
  10890. * row:remove:                            Table Operations.
  10891. * row:remove*:                           Table Operations.
  10892. * row:retrieve:                          Table Operations.
  10893. * row:retrieve*:                         Table Operations.
  10894. * row:update:                            Table Operations.
  10895. * row:update*:                           Table Operations.
  10896. * scanf:                                 Standard Formatted Input.
  10897. * scanf-read-list:                       Standard Formatted Input.
  10898. * scheme-report-environment:             Eval.
  10899. * schmooz:                               Schmooz.
  10900. * secant:find-bracketed-root:            Root Finding.
  10901. * secant:find-root:                      Root Finding.
  10902. * seed->random-state:                    Random Numbers.
  10903. * serve-urlencoded-command:              HTML HTTP and CGI.
  10904. * set:                                   Setters.
  10905. * set-:                                  Structures.
  10906. * set-difference:                        Lists as sets.
  10907. * Setter:                                Collections.
  10908. * setter:                                Setters.
  10909. * singleton-wt-tree:                     Construction of Weight-Balanced Trees.
  10910. * size <1>:                              Collections.
  10911. * size:                                  Yasos interface.
  10912. * slib:error:                            System.
  10913. * slib:eval:                             System.
  10914. * slib:eval-load:                        System.
  10915. * slib:exit:                             System.
  10916. * slib:load:                             System.
  10917. * slib:load-compiled:                    System.
  10918. * slib:load-source:                      System.
  10919. * slib:report:                           Configuration.
  10920. * slib:report-version:                   Configuration.
  10921. * slib:warn:                             System.
  10922. * software-type:                         Configuration.
  10923. * some:                                  Lists as sets.
  10924. * sort:                                  Sorting.
  10925. * sort!:                                 Sorting.
  10926. * sorted?:                               Sorting.
  10927. * soundex:                               Hashing.
  10928. * sprintf:                               Standard Formatted Output.
  10929. * sscanf:                                Standard Formatted Input.
  10930. * stack:                                 Trace.                               |
  10931. * stack-all:                             Debug.                               |
  10932. * string->list:                          Rev4 Optional Procedures.
  10933. * string-capitalize:                     String-Case.
  10934. * string-captialize!:                    String-Case.
  10935. * string-ci->symbol:                     String-Case.
  10936. * string-copy:                           Rev4 Optional Procedures.
  10937. * string-downcase:                       String-Case.
  10938. * string-downcase!:                      String-Case.
  10939. * string-fill!:                          Rev4 Optional Procedures.
  10940. * string-index:                          String Search.
  10941. * string-index-ci:                       String Search.
  10942. * string-join:                           Batch.
  10943. * string-null?:                          Rev2 Procedures.
  10944. * string-reverse-index:                  String Search.
  10945. * string-reverse-index-ci:               String Search.
  10946. * string-subst:                          String Search.
  10947. * string-upcase:                         String-Case.
  10948. * string-upcase!:                        String-Case.
  10949. * sub-vicinity:                          Vicinity.
  10950. * subst:                                 Tree Operations.
  10951. * substq:                                Tree Operations.
  10952. * substring-ci?:                         String Search.
  10953. * substring-fill!:                       Rev2 Procedures.
  10954. * substring-move-left!:                  Rev2 Procedures.
  10955. * substring-move-right!:                 Rev2 Procedures.
  10956. * substring?:                            String Search.
  10957. * substv:                                Tree Operations.
  10958. * supported-key-type?:                   Base Table.
  10959. * supported-type?:                       Base Table.
  10960. * symmetric:modulus:                     Modular Arithmetic.
  10961. * sync-base:                             Base Table.
  10962. * syncase:eval:                          Syntax-Case Macros.
  10963. * syncase:expand:                        Syntax-Case Macros.
  10964. * syncase:load:                          Syntax-Case Macros.
  10965. * synclo:eval:                           Syntactic Closures.
  10966. * synclo:expand:                         Syntactic Closures.
  10967. * synclo:load:                           Syntactic Closures.
  10968. * syntax-rules:                          Macro by Example.
  10969. * system:                                System Interface.
  10970. * table->html:                           HTML HTTP and CGI.
  10971. * table->page:                           HTML HTTP and CGI.
  10972. * table-exists?:                         Relational Database Operations.
  10973. * table-name->filename:                  HTML HTTP and CGI.
  10974. * TAG:                                   Structures.
  10975. * tek40:draw:                            Tektronix Graphics Support.
  10976. * tek40:graphics:                        Tektronix Graphics Support.
  10977. * tek40:init:                            Tektronix Graphics Support.
  10978. * tek40:linetype:                        Tektronix Graphics Support.
  10979. * tek40:move:                            Tektronix Graphics Support.
  10980. * tek40:put-text:                        Tektronix Graphics Support.
  10981. * tek40:reset:                           Tektronix Graphics Support.
  10982. * tek40:text:                            Tektronix Graphics Support.
  10983. * tek41:draw:                            Tektronix Graphics Support.
  10984. * tek41:encode-int:                      Tektronix Graphics Support.
  10985. * tek41:encode-x-y:                      Tektronix Graphics Support.
  10986. * tek41:graphics:                        Tektronix Graphics Support.
  10987. * tek41:init:                            Tektronix Graphics Support.
  10988. * tek41:move:                            Tektronix Graphics Support.
  10989. * tek41:point:                           Tektronix Graphics Support.
  10990. * tek41:reset:                           Tektronix Graphics Support.
  10991. * time-zone:                             Time Zone.
  10992. * tmpnam:                                Input/Output.
  10993. * tok:char-group:                        Token definition.
  10994. * topological-sort:                      Topological Sort.
  10995. * trace:                                 Trace.
  10996. * trace-all:                             Debug.
  10997. * tracef:                                Trace.
  10998. * track:                                 Trace.                               |
  10999. * track-all:                             Debug.                               |
  11000. * transcript-off:                        Transcripts.
  11001. * transcript-on:                         Transcripts.
  11002. * transformer:                           Syntactic Closures.
  11003. * truncate-up-to:                        Batch.
  11004. * tsort:                                 Topological Sort.
  11005. * two-arg:-:                             Multi-argument / and -.
  11006. * two-arg:/:                             Multi-argument / and -.
  11007. * two-arg:apply:                         Multi-argument Apply.
  11008. * type-of:                               Non-List functions.
  11009. * tz:params:                             Time Zone.
  11010. * tzset:                                 Time Zone.
  11011. * unbreak:                               Breakpoints.
  11012. * unbreakf:                              Breakpoints.
  11013. * union:                                 Lists as sets.
  11014. * unmake-method!:                        Object.
  11015. * unstack:                               Trace.                               |
  11016. * untrace:                               Trace.
  11017. * untracef:                              Trace.
  11018. * untrack:                               Trace.                               |
  11019. * user-email-address:                    System Interface.
  11020. * user-vicinity:                         Vicinity.
  11021. * values:                                Values.
  11022. * variant-case:                          Structures.
  11023. * vector->list:                          Rev4 Optional Procedures.
  11024. * vector-fill!:                          Rev4 Optional Procedures.
  11025. * with-input-from-file:                  With-File.
  11026. * with-output-to-file:                   With-File.
  11027. * write-base:                            Base Table.
  11028. * write-byte:                            Byte.
  11029. * write-database:                        Relational Database Operations.
  11030. * write-line:                            Line I/O.
  11031. * wt-tree/add:                           Basic Operations on Weight-Balanced Trees.
  11032. * wt-tree/add!:                          Basic Operations on Weight-Balanced Trees.
  11033. * wt-tree/delete:                        Basic Operations on Weight-Balanced Trees.
  11034. * wt-tree/delete!:                       Basic Operations on Weight-Balanced Trees.
  11035. * wt-tree/delete-min:                    Indexing Operations on Weight-Balanced Trees.
  11036. * wt-tree/delete-min!:                   Indexing Operations on Weight-Balanced Trees.
  11037. * wt-tree/difference:                    Advanced Operations on Weight-Balanced Trees.
  11038. * wt-tree/empty?:                        Basic Operations on Weight-Balanced Trees.
  11039. * wt-tree/fold:                          Advanced Operations on Weight-Balanced Trees.
  11040. * wt-tree/for-each:                      Advanced Operations on Weight-Balanced Trees.
  11041. * wt-tree/index:                         Indexing Operations on Weight-Balanced Trees.
  11042. * wt-tree/index-datum:                   Indexing Operations on Weight-Balanced Trees.
  11043. * wt-tree/index-pair:                    Indexing Operations on Weight-Balanced Trees.
  11044. * wt-tree/intersection:                  Advanced Operations on Weight-Balanced Trees.
  11045. * wt-tree/lookup:                        Basic Operations on Weight-Balanced Trees.
  11046. * wt-tree/member?:                       Basic Operations on Weight-Balanced Trees.
  11047. * wt-tree/min:                           Indexing Operations on Weight-Balanced Trees.
  11048. * wt-tree/min-datum:                     Indexing Operations on Weight-Balanced Trees.
  11049. * wt-tree/min-pair:                      Indexing Operations on Weight-Balanced Trees.
  11050. * wt-tree/rank:                          Indexing Operations on Weight-Balanced Trees.
  11051. * wt-tree/set-equal?:                    Advanced Operations on Weight-Balanced Trees.
  11052. * wt-tree/size:                          Basic Operations on Weight-Balanced Trees.
  11053. * wt-tree/split<:                        Advanced Operations on Weight-Balanced Trees.
  11054. * wt-tree/split>:                        Advanced Operations on Weight-Balanced Trees.
  11055. * wt-tree/subset?:                       Advanced Operations on Weight-Balanced Trees.
  11056. * wt-tree/union:                         Advanced Operations on Weight-Balanced Trees.
  11057. * wt-tree?:                              Basic Operations on Weight-Balanced Trees.
  11058.  
  11059. Variable Index
  11060. **************
  11061.  
  11062.   This is an alphabetical list of all the global variables in SLIB.
  11063.  
  11064. * Menu:
  11065.  
  11066. * *catalog*:                             Require.
  11067. * *features*:                            Require.
  11068. * *html:output-port*:                    HTML HTTP and CGI.
  11069. * *modules*:                             Require.
  11070. * *optarg*:                              Getopt.
  11071. * *optind*:                              Getopt.
  11072. * *qp-width*:                            Quick Print.
  11073. * *random-state*:                        Random Numbers.
  11074. * *ruleset*:                             Commutative Rings.
  11075. * *syn-defs*:                            Ruleset Definition and Use.
  11076. * *syn-ignore-whitespace*:               Ruleset Definition and Use.
  11077. * *timezone*:                            Time Zone.
  11078. * batch:platform:                        Batch.
  11079. * catalog-id:                            Base Table.
  11080. * char-code-limit:                       Configuration.
  11081. * charplot:height:                       Plotting.
  11082. * charplot:width:                        Plotting.
  11083. * column-domains:                        Table Operations.
  11084. * column-foreigns:                       Table Operations.
  11085. * column-names:                          Table Operations.
  11086. * column-types:                          Table Operations.
  11087. * daylight?:                             Time Zone.
  11088. * debug:max-count:                       Trace.                               |
  11089. * distribute*:                           Commutative Rings.
  11090. * distribute/:                           Commutative Rings.
  11091. * most-positive-fixnum:                  Configuration.
  11092. * nil:                                   Legacy.
  11093. * number-wt-type:                        Construction of Weight-Balanced Trees.
  11094. * primary-limit:                         Table Operations.
  11095. * prime:prngs:                           Prime Numbers.
  11096. * prime:trials:                          Prime Numbers.
  11097. * slib:form-feed:                        Configuration.
  11098. * slib:tab:                              Configuration.
  11099. * stderr:                                Standard Formatted I/O.
  11100. * stdin:                                 Standard Formatted I/O.
  11101. * stdout:                                Standard Formatted I/O.
  11102. * string-wt-type:                        Construction of Weight-Balanced Trees.
  11103. * t:                                     Legacy.
  11104. * tok:decimal-digits:                    Token definition.
  11105. * tok:lower-case:                        Token definition.
  11106. * tok:upper-case:                        Token definition.
  11107. * tok:whitespaces:                       Token definition.
  11108. * tzname:                                Time Zone.
  11109.  
  11110. Concept and Feature Index
  11111. *************************
  11112.  
  11113. * Menu:
  11114.  
  11115. * alist:                                 Association Lists.
  11116. * alist-table <1>:                       Creating and Opening Relational Databases.
  11117. * alist-table:                           Base Table.
  11118. * ange-ftp:                              System Interface.
  11119. * array:                                 Arrays.
  11120. * array-for-each:                        Array Mapping.
  11121. * attribute-value:                       HTML HTTP and CGI.
  11122. * balanced binary trees:                 Weight-Balanced Trees.
  11123. * batch:                                 Batch.
  11124. * binary trees:                          Weight-Balanced Trees.
  11125. * binary trees, as discrete maps:        Weight-Balanced Trees.
  11126. * binary trees, as sets:                 Weight-Balanced Trees.
  11127. * break:                                 Breakpoints.
  11128. * byte:                                  Byte.
  11129. * calendar time <1>:                     Posix Time.
  11130. * calendar time:                         Time and Date.
  11131. * Calendar-Time:                         Posix Time.
  11132. * caltime:                               Posix Time.
  11133. * careful:                               Commutative Rings.
  11134. * catalog:                               Requesting Features.
  11135. * Catalog File:                          Library Catalogs.
  11136. * chapter-order:                         Chapter Ordering.
  11137. * charplot:                              Plotting.
  11138. * collect:                               Collections.
  11139. * command line:                          Command Line.
  11140. * commentfix:                            Precedence Parsing Overview.
  11141. * common-list-functions <1>:             Common List Functions.
  11142. * common-list-functions:                 Collections.
  11143. * commutative-ring:                      Commutative Rings.
  11144. * Coordinated Universal Time:            Posix Time.
  11145. * database-utilities <1>:                Database Utilities.
  11146. * database-utilities:                    Batch.
  11147. * debug <1>:                             Breakpoints.
  11148. * debug:                                 Debug.
  11149. * defmacroexpand <1>:                    Pretty-Print.
  11150. * defmacroexpand:                        Defmacro.
  11151. * delim:                                 Precedence Parsing Overview.
  11152. * discrete maps, using binary trees:     Weight-Balanced Trees.
  11153. * dynamic:                               Dynamic Data Type.
  11154. * dynamic-wind:                          Dynamic-Wind.
  11155. * Euclidean Domain:                      Commutative Rings.
  11156. * factor:                                Prime Numbers.
  11157. * feature <1>:                           About this manual.
  11158. * feature <2>:                           Requesting Features.
  11159. * feature:                               Feature.
  11160. * fft:                                   Fast Fourier Transform.
  11161. * fluid-let <1>:                         Database Utilities.
  11162. * fluid-let:                             Fluid-Let.
  11163. * form:                                  HTML HTTP and CGI.
  11164. * format:                                Format.
  11165. * generic-write:                         Generic-Write.
  11166. * getit:                                 System Interface.
  11167. * getopt <1>:                            Database Utilities.
  11168. * getopt:                                Getopt.
  11169. * glob <1>:                              Batch.
  11170. * glob:                                  Filenames.
  11171. * hash:                                  Hashing.
  11172. * hash-table:                            Hash Tables.
  11173. * HOME <1>:                              Vicinity.
  11174. * HOME:                                  Library Catalogs.
  11175. * homecat:                               Catalog Compilation.
  11176. * implcat:                               Catalog Compilation.
  11177. * infix:                                 Precedence Parsing Overview.
  11178. * inmatchfix:                            Precedence Parsing Overview.
  11179. * Left Denotation, led:                  Nud and Led Definition.
  11180. * line-i:                                Line I/O.
  11181. * logical:                               Bit-Twiddling.
  11182. * macro <1>:                             Repl.
  11183. * macro:                                 R4RS Macros.
  11184. * macro-by-example:                      Macro by Example.
  11185. * macros-that-work:                      Macros That Work.
  11186. * make-crc:                              Cyclic Checksum.
  11187. * match:                                 Base Table.
  11188. * match-keys <1>:                        Table Operations.                    |
  11189. * match-keys:                            Base Table.                          |
  11190. * matchfix:                              Precedence Parsing Overview.
  11191. * minimize:                              Minimizing.                          |
  11192. * minimum field width (printf):          Standard Formatted Output.
  11193. * mkimpcat.scm:                          Catalog Compilation.
  11194. * mklibcat.scm:                          Catalog Compilation.
  11195. * modular:                               Modular Arithmetic.
  11196. * multiarg-apply:                        Multi-argument Apply.
  11197. * mutliarg:                              Multi-argument / and -.
  11198. * nary:                                  Precedence Parsing Overview.
  11199. * net-clients:                           System Interface.
  11200. * nofix:                                 Precedence Parsing Overview.
  11201. * Null Denotation, nud:                  Nud and Led Definition.
  11202. * object:                                Object.
  11203. * object->string:                        Object-To-String.
  11204. * oop:                                   Yasos.
  11205. * option, run-time-loadable:             Weight-Balanced Trees.
  11206. * options file:                          Command Line.
  11207. * parameters <1>:                        Database Utilities.
  11208. * parameters <2>:                        Batch.
  11209. * parameters:                            Parameter lists.
  11210. * parse:                                 Precedence Parsing.
  11211. * plain-text:                            HTML HTTP and CGI.
  11212. * posix-time:                            Posix Time.
  11213. * postfix:                               Precedence Parsing Overview.
  11214. * pprint-file:                           Pretty-Print.
  11215. * PRE:                                   HTML HTTP and CGI.
  11216. * precedence:                            Precedence Parsing.
  11217. * precision (printf):                    Standard Formatted Output.
  11218. * prefix:                                Precedence Parsing Overview.
  11219. * prestfix:                              Precedence Parsing Overview.
  11220. * pretty-print:                          Pretty-Print.
  11221. * primes:                                Prime Numbers.
  11222. * printf:                                Standard Formatted Output.
  11223. * priority-queue:                        Priority Queues.
  11224. * PRNG:                                  Random Numbers.
  11225. * process:                               Multi-Processing.
  11226. * promise:                               Promises.
  11227. * qp <1>:                                Quick Print.
  11228. * qp:                                    Getopt.
  11229. * query-string:                          HTML HTTP and CGI.
  11230. * queue:                                 Queues.
  11231. * random:                                Random Numbers.
  11232. * rationalize:                           Rationalize.
  11233. * read-command:                          Command Line.
  11234. * record:                                Records.
  11235. * relational-database:                   Relational Database.
  11236. * repl <1>:                              Repl.
  11237. * repl:                                  Syntax-Case Macros.
  11238. * rev2-procedures:                       Rev2 Procedures.
  11239. * rev3-report:                           Coding Guidelines.                   |
  11240. * rev4-optional-procedures:              Rev4 Optional Procedures.
  11241. * ring, commutative:                     Commutative Rings.
  11242. * RNG:                                   Random Numbers.
  11243. * root:                                  Root Finding.
  11244. * run-time-loadable option:              Weight-Balanced Trees.
  11245. * scanf:                                 Standard Formatted Input.
  11246. * schmooz:                               Schmooz.
  11247. * session:                               Feature.
  11248. * sets, using binary trees:              Weight-Balanced Trees.
  11249. * sierpinski:                            Hashing.
  11250. * sitecat:                               Catalog Compilation.
  11251. * slibcat:                               Catalog Compilation.
  11252. * sort:                                  Sorting.
  11253. * soundex:                               Hashing.
  11254. * stdio:                                 Standard Formatted I/O.
  11255. * string-case:                           String-Case.
  11256. * string-port:                           String Ports.
  11257. * string-search:                         String Search.
  11258. * struct:                                Structures.
  11259. * syntactic-closures:                    Syntactic Closures.
  11260. * syntax-case:                           Syntax-Case Macros.
  11261. * time:                                  Time and Date.
  11262. * time-zone:                             Time Zone.
  11263. * topological-sort:                      Topological Sort.
  11264. * trace:                                 Trace.
  11265. * transcript:                            Transcripts.
  11266. * tree:                                  Tree Operations.
  11267. * trees, balanced binary:                Weight-Balanced Trees.
  11268. * tsort:                                 Topological Sort.
  11269. * TZ-string:                             Time Zone.
  11270. * Uniform Resource Locator:              System Interface.
  11271. * Unique Factorization:                  Commutative Rings.
  11272. * URI:                                   HTML HTTP and CGI.                   |
  11273. * usercat:                               Catalog Compilation.
  11274. * UTC:                                   Posix Time.
  11275. * values:                                Values.
  11276. * weight-balanced binary trees:          Weight-Balanced Trees.
  11277. * wild-card:                             Base Table.
  11278. * with-file:                             With-File.
  11279. * wt-tree:                               Weight-Balanced Trees.
  11280. * yasos:                                 Yasos.
  11281.  
  11282.  
  11283. 
  11284. Tag Table:
  11285. Node: Top1137
  11286. Node: The Library System1851
  11287. Node: Feature2165
  11288. Node: Requesting Features3115
  11289. Node: Library Catalogs4474
  11290. Node: Catalog Compilation6926
  11291. Node: Built-in Support9736
  11292. Node: Require10367
  11293. Node: Vicinity12860
  11294. Node: Configuration15827
  11295. Node: Input/Output18768
  11296. Node: Legacy20367
  11297. Node: System21209
  11298. Node: About this manual23701
  11299. Node: Scheme Syntax Extension Packages24258
  11300. Node: Defmacro24943
  11301. Node: R4RS Macros26958
  11302. Node: Macro by Example28213
  11303. Node: Macros That Work31089
  11304. Node: Syntactic Closures37147
  11305. Node: Syntax-Case Macros54580
  11306. Node: Fluid-Let58707
  11307. Node: Yasos59648
  11308. Node: Yasos terms60441
  11309. Node: Yasos interface61465
  11310. Node: Setters63542
  11311. Node: Yasos examples66184
  11312. Node: Textual Conversion Packages69178
  11313. Node: Precedence Parsing69754
  11314. Node: Precedence Parsing Overview70417
  11315. Node: Ruleset Definition and Use72618
  11316. Node: Token definition74999
  11317. Node: Nud and Led Definition77268
  11318. Node: Grammar Rule Definition79717
  11319. Node: Format87291
  11320. Node: Format Interface87539
  11321. Node: Format Specification89276
  11322. Node: Standard Formatted I/O99333
  11323. Node: Standard Formatted Output99899
  11324. Node: Standard Formatted Input109350
  11325. Node: Programs and Arguments116009
  11326. Node: Getopt116522
  11327. Node: Command Line122364
  11328. Node: Parameter lists125553
  11329. Node: Getopt Parameter lists129190
  11330. Node: Filenames131385
  11331. Node: Batch134615
  11332. Node: HTML HTTP and CGI142411
  11333. Node: Printing Scheme152837
  11334. Node: Generic-Write153160
  11335. Node: Object-To-String154563
  11336. Node: Pretty-Print154967
  11337. Node: Time and Date156913
  11338. Node: Time Zone157940
  11339. Node: Posix Time162502
  11340. Node: Common-Lisp Time164638
  11341. Node: Vector Graphics166217
  11342. Node: Tektronix Graphics Support166406
  11343. Node: Schmooz167780
  11344. Node: Mathematical Packages172006
  11345. Node: Bit-Twiddling172678
  11346. Node: Modular Arithmetic177269
  11347. Node: Prime Numbers179403
  11348. Node: Random Numbers181087
  11349. Node: Fast Fourier Transform185723
  11350. Node: Cyclic Checksum186641
  11351. Node: Plotting188359
  11352. Node: Root Finding190934
  11353. Node: Minimizing195000
  11354. Node: Commutative Rings198712
  11355. Node: Determinant210175
  11356. Node: Database Packages210473
  11357. Node: Base Table210737
  11358. Node: Relational Database221625
  11359. Node: Motivations222409
  11360. Node: Creating and Opening Relational Databases227456
  11361. Node: Relational Database Operations229888
  11362. Node: Table Operations232685
  11363. Node: Catalog Representation240563
  11364. Node: Unresolved Issues243461
  11365. Node: Database Utilities246412
  11366. Node: Database Reports262067
  11367. Node: Database Browser264822
  11368. Node: Weight-Balanced Trees265883
  11369. Node: Construction of Weight-Balanced Trees269753
  11370. Node: Basic Operations on Weight-Balanced Trees273203
  11371. Node: Advanced Operations on Weight-Balanced Trees276168
  11372. Node: Indexing Operations on Weight-Balanced Trees282190
  11373. Node: Other Packages286104
  11374. Node: Data Structures286503
  11375. Node: Arrays287222
  11376. Node: Array Mapping290176
  11377. Node: Association Lists292093
  11378. Node: Byte294344
  11379. Node: Collections296575
  11380. Node: Dynamic Data Type302682
  11381. Node: Hash Tables303943
  11382. Node: Hashing306060
  11383. Node: Object310835
  11384. Node: Priority Queues319072
  11385. Node: Queues319915
  11386. Node: Records321041
  11387. Node: Structures324552
  11388. Node: Procedures325852
  11389. Node: Common List Functions326539
  11390. Node: List construction326963
  11391. Node: Lists as sets328626
  11392. Node: Lists as sequences333987
  11393. Node: Destructive list operations339233
  11394. Node: Non-List functions341897
  11395. Node: Tree Operations343245
  11396. Node: Chapter Ordering344791
  11397. Node: Sorting346411
  11398. Node: Topological Sort352188
  11399. Node: String-Case353875
  11400. Node: String Ports354496
  11401. Node: String Search355260
  11402. Node: Line I/O357627
  11403. Node: Multi-Processing359286
  11404. Node: Standards Support360370
  11405. Node: With-File361025
  11406. Node: Transcripts361301
  11407. Node: Rev2 Procedures361622
  11408. Node: Rev4 Optional Procedures363329
  11409. Node: Multi-argument / and -363899
  11410. Node: Multi-argument Apply364550
  11411. Node: Rationalize365036
  11412. Node: Promises367280
  11413. Node: Dynamic-Wind367697
  11414. Node: Eval368951
  11415. Node: Values372288
  11416. Node: Session Support373075
  11417. Node: Repl373543
  11418. Node: Quick Print374826
  11419. Node: Debug375939
  11420. Node: Breakpoints377434
  11421. Node: Trace379577
  11422. Node: System Interface385239
  11423. Node: Extra-SLIB Packages388994
  11424. Node: About SLIB392007
  11425. Node: Installation392688
  11426. Node: Porting394538
  11427. Node: Coding Guidelines396135
  11428. Node: Copyrights398420
  11429. Node: Index401784
  11430. 
  11431. End Tag Table
  11432.